⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5.htm

📁 vb基础教程源文件 处学者必备
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=GB2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List href="./5.files/filelist.xml">
<title>无标题文档</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>oem</o:Author>
  <o:Template>Normal</o:Template>
  <o:LastAuthor>oem</o:LastAuthor>
  <o:Revision>3</o:Revision>
  <o:TotalTime>9</o:TotalTime>
  <o:LastPrinted>2006-07-04T09:44:00Z</o:LastPrinted>
  <o:Created>2006-07-01T08:05:00Z</o:Created>
  <o:LastSaved>2006-07-04T09:46:00Z</o:LastSaved>
  <o:Pages>5</o:Pages>
  <o:Words>697</o:Words>
  <o:Characters>3978</o:Characters>
  <o:Lines>33</o:Lines>
  <o:Paragraphs>7</o:Paragraphs>
  <o:CharactersWithSpaces>4885</o:CharactersWithSpaces>
  <o:Version>9.2812</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:Zoom>80</w:Zoom>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:Compatibility>
   <w:UseFELayout/>
  </w:Compatibility>
 </w:WordDocument>
</xml><![endif]-->
<style>
<!--
 /* Font Definitions */
@font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimSun;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
	{font-family:"\@宋体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
 /* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:宋体;
	mso-bidi-font-family:"Times New Roman";}
p.MsoFooter, li.MsoFooter, div.MsoFooter
	{margin:0cm;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	tab-stops:center 207.65pt right 415.3pt;
	layout-grid-mode:char;
	font-size:9.0pt;
	font-family:宋体;
	mso-bidi-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
p
	{margin-right:0cm;
	mso-margin-top-alt:auto;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:宋体;
	mso-bidi-font-family:"Times New Roman";}
 /* Page Definitions */
@page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:42.55pt;
	mso-footer-margin:49.6pt;
	mso-page-numbers:76;
	mso-even-footer:url("./5.files/header.htm") ef1;
	mso-footer:url("./5.files/header.htm") f1;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
</head>

<body lang=ZH-CN link=blue vlink=blue style='tab-interval:21.0pt'>

<div class=Section1>

<h2>第五章<span lang=EN-US> VB中的数组 </span></h2>

<h2 align=center style='text-align:center'><strong><span lang=EN-US
style='font-weight:normal'>1 数组的概念</span></strong></h2>

<p><strong><span lang=EN-US>1. 引例 </span></strong></p>

<p>  求<span lang=EN-US> 100 个学生的平均成绩及超过平均成绩的人数。 </span></p>

<p>如果用一般变量来表示成绩,需要用<span lang=EN-US> 100 个变量,如: mark1 、 mary2 、…… mark100 。若用数组,可以只用一个来表示
mark ( 1 <br>
<br>
To 100 )。 </span></p>

<p><strong><span lang=EN-US>2. 基本概念 </span></strong></p>

<p><strong>数组 </strong>:是同类型变量的一个有序的集合。 </p>

<p>如:<span lang=EN-US> A ( 1 To 100 ),表示一个包含 100 个数组元素的名为 A 的数组。 </span></p>

<p><strong>数组元素 </strong>: 即数组中的变量。用下标表示数组中的各个元素。 </p>

<p>表示方法: <strong>数组名 </strong>(<span lang=EN-US> P1 , P2 , ……) </span></p>

<p>其中<span lang=EN-US> P1 、 P2 表示元素在数组中的排列位置,称为“下标”。 </span></p>

<p>如:<span lang=EN-US> A ( 3 , 2 )代表二维数组 A 中第 3 行第 2 列上的那个元素。 </span></p>

<p><strong>数组维数 </strong>: 由数组元素中下标的个数决定,一个下标表示一维数组,二个下标表示二维数组。 </p>

<p><span lang=EN-US>VB 中有一维数组、二维数组、……最多 60 维数组。 </span></p>

<p><strong>下标: </strong>下标表示顺序号,每个数组有一个唯一的顺序号,下标不能超过数组声明时的上、下界范围。下标可以是整型的常数、变量、表达式,甚至又是一个数组元素。
</p>

<p>下标的取值范围是:下界<span lang=EN-US> To 上界 ,缺省下界时,系统默认取 0 。 </span></p>

<p><strong><span lang=EN-US>3. 数组声明 </span></strong></p>

<p>数组必须先声明后使用。声明数组就是让系统在内存中分配一个连续的区域,用来存储数组元素。 </p>

<p><strong>声明内容 </strong>: <strong>数组名、类型、维数、数组大小 </strong>。 </p>

<p>一般情况下,数组中各元素类型必须相同,但若数组为<span lang=EN-US> Variant 时,可包含不同类型的数据。 </span></p>

<p><strong>静态数组: </strong>声明时确定了大小的数组。 </p>

<p><strong>动态数组: </strong>声明时没有给定数组大小(省略了括号中的下标),使用时需要用<span lang=EN-US> ReDim 语句重新指出其大小。
</span></p>

<p>使用动态数组的优点是根据用户需要,有效地利用存储空间,它是在程序执行到<span lang=EN-US> ReDim 语句时才分配存储单元,而静态数组是在程序编译时分配存储单元。
</span></p>

<p align=center style='text-align:center'><strong><span lang=EN-US>5.2 静态数组及声明 </span></strong></p>

<p><strong><span lang=EN-US>1. 一维数组 </span></strong></p>

<p>静态一维数组的声明形式: </p>

<p><strong><span lang=EN-US>Dim 数组名 ( 下标 ) [ As 类型 ] </span></strong></p>

<p><strong>说明: </strong>(<span lang=EN-US> 1 )下标必须为常数,不可以为表达式或变量; <br>
( 2 )下标下界最小为 -32768 ,最大上界为 32767 ; 省略下界,其默认值为为 0 ,一维数组的大小为:上界 - 下界 +1 <br>
( 3 ) 如果省略类型,则为变体型 </span></p>

<p><strong>例 </strong>: (<span lang=EN-US> 1 ) Dim A ( 10 ) As Integer <br>
声明了 A 是数组名、整型、一维数组、有 11 个元素,下标的范围是 0 ~ 10 。 <br>
( 2 ) Dim B ( -3 To 5 ) As String*3 <br>
声明了 B 是数组名、字符串型、一维数组、有 9 个元素,下标的范围是 -3 ~ 5 ,每个元素最多存放 3 个字符。 </span></p>

<p><strong><span lang=EN-US>2. 多维数组 </span></strong></p>

<p>静态多维数组的声明形式:<span lang=EN-US> <br>
<strong>Dim 数组名 ( 下标 1[ , 下标 2 … ] ) [ As 类型 ] </strong></span></p>

<p><strong>说明 </strong>: (<span lang=EN-US> 1 )下标个数决定数组的维数,最多 60 维。 <br>
( 2 )每一维的大小 = 上界 - 下界 +1 ;数组的大小 = 每一维大小的乘积。 </span></p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -