【软件自动化测试-QTP实战技能 28】== QTP_VbsTraining:Array Basics

作者:xuyubo
时间:2012/10/31 版权所有,侵权必究。
出处:http://blog.csdn.net/xuyubotest

Array Basics:

Some basic info about creating and using arrays.

' 简单的定义Array
Dim strCustomers()
 
' 定义一个Array,然后赋值
Dim strStaff
strStaff = Array("A","B","C")

' Yet another way is to use the split command to create and populate the array
Dim strProductArray
strProductArray = "K,Y,M"
strProductArray = Split(strProductArray, ",")

' 用For Each循环获取Array中的数据
Dim strItem
For Each strItem In strProductArray
    MsgBox strItem
Next


' This will also itterate through the loop
Dim intCount
For intCount = LBound(strProductArray) To UBound(strProductArray)
    Msgbox strProductArray(intCount)
Next


' This will itterate through the array backwards
For intCount = UBound(strProductArray) To LBound(strProductArray) Step -1
    Msgbox strProductArray(intCount)
Next


' To add extra data to an array use Redim Preserve
Redim Preserve strProductArray(3)

strProductArray(3) = "Mice"


ReDim 语句通常用于指定或修改动态数组的大小,这些数组已用带有空括号的PrivatePublicDim 语句(没有维数下标)正式声明过。可以重复使用ReDim 语句更改数组维数和元素数目。

如果使用了 Preserve 关键字,就只能调整数组最后维的大小,并且不能改变数组的维数。例如,如果数组只有一维,就可以修改该数组的大小,因为该维是最后的也是仅有的一维。但是,如果数组有两个或更多维,就只能改变末维的大小并保留数组内容。

这个例子说明如何不擦掉该数组中存在的数据,而增加动态数组的终止维数。


' To store the contents of an array into one string, use Join
Msgbox Join(strProductArray, ",")

' To delete the contents of an array, use the Erase command

Erase strProductArray




你可能感兴趣的:(【软件自动化测试-QTP实战技能 28】== QTP_VbsTraining:Array Basics)