字典 Scripting.Dictionary
1、CreateObject(“Scripting.Dictionary”)
(1)Add
(2)Remove
//定义一个字典
Set objDic = CreateObject("Scripting.Dictionary")
objDic.Add "1","aa"
objDic.Add "2","bb"
objDic.Add "3","cc"
objDic.Add "4","dd"
//移除一个
objDic.Remove("3")
//显示字典个数
msgbox objDic.Count
//字典中所有key组成一个数组,下标从0开始
key = objDic.Keys
//显示数组key中第2个元素,值为2
msgbox key(1)
//根据key值获取字典中的数据
value=objDic.Item("1")
msgbox value
----------
//动态数组
Dim Arr()
For i = 1 To 3
ReDim preserve arr(i-1)
arr(i-1)=i
Next
msgbox ubound(Arr)
msgbox Arr(1)
----------
//excel表格
'Set ExcelApp=CreateObject("Excel.Application")
'Set ExcelPath=ExcelApp.Workbooks.Open("D:\UFT\data.xlsx")
'Set ExcelSheet=ExcelPath.Worksheets("Sheet1").UsedRange
'rowCount=ExcelSheet.Rows.count
'columnCount=ExcelSheet.Columns.count
'ExcelPath.Close
'ExcelApp.Quit
'set ExcelApp = Nothing
----------
//excel
Function excel(path,sheet)
Dim Arr()
Set ExcelApp=CreateObject("Excel.Application")
Set ExcelPath=ExcelApp.Workbooks.Open(path)
Set ExcelSheet=ExcelPath.Worksheets(sheet).UsedRange
rowCount=ExcelSheet.Rows.count
columnCount=ExcelSheet.Columns.count
For i = 1 To rowCount
ReDim preserve Arr(i-1)
Arr(i-1)=ExcelSheet.cells(i,1)
Next
Set ExcelSheet=NOthing
ExcelPath.Close
ExcelApp.Quit
set ExcelApp = Nothing
excel =Arr
End Function
----------
//调用函数excel
b = excel("D:\UFT\data.xlsx","sheet1")
msgbox ubound (b)
msgbox b(0)
For i = 1 To ubound(b)
msgbox b(i)
Next
Set fromCity =Wpfwindow("HPE MyFlight Sample Applicatio").WpfComboBox("fromCity")
For i = 0 To fromCity.GetItemsCount -1
If fromCity.GetItem(i)=b(i) Then
print i& " is right"
else
print i& " is wrong"
End If
Next