VB 中的数组使用

2025-05-06 08:47:34
admin

一、数组概念

一组相同数据类型的集合

二、声明数组索引的缺省下届

语法

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

Copyright © 2088 2015女排世界杯_法国世界杯夺冠 - pgcnz.com All Rights Reserved.
友情链接