【软件自动化测试-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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值