一、數組概念
一組相同數據類型的集合
二、聲明數組索引的缺省下屆
語法
Option Base {0 | 1}
三、聲明數組
1、聲明靜態數組,數組的大小不變
dim nodes(10) as string
2、聲明動態數組,數組的大小可以改變
dim nodes() as string
redim nodes(20) as string
四、數組元素賦值
數組中的各元素,必須個別指定其值。
實例:
將字符串spath= “01模塊測試\02模塊專用\09掃描類\04.A4紙掃描儀(未評審)\01.外觀結構” 以“\” 為界划分為5個字符串保存到數組nodes() 中
Option Base 1 Dim nodes() As String '用於保存節點的名稱 'MsgBox InStr(tempPath, "\") numOfNodes = 0 While (InStr(tempPath, "\") > 0) numOfNodes = numOfNodes + 1 tempPath = Right(tempPath, Len(tempPath) - InStr(tempPath, "\")) Wend '將路徑保存為數組 ReDim nodes(numOfNodes + 1) tempPath = spath For i = 1 To numOfNodes nodes(i) = Left(tempPath, InStr(tempPath, "\") - 1) tempPath = Right(tempPath, Len(tempPath) - InStr(tempPath, "\")) Next nodes(numOfNodes + 1) = tempPath