本文主要是介绍UFT_基础14_动态数组重构excel,字典,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
字典 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 3ReDim 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).UsedRangerowCount=ExcelSheet.Rows.countcolumnCount=ExcelSheet.Columns.countFor i = 1 To rowCountReDim preserve Arr(i-1)Arr(i-1)=ExcelSheet.cells(i,1)NextSet ExcelSheet=NOthingExcelPath.CloseExcelApp.Quitset ExcelApp = Nothingexcel =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)
NextSet fromCity =Wpfwindow("HPE MyFlight Sample Applicatio").WpfComboBox("fromCity")For i = 0 To fromCity.GetItemsCount -1If fromCity.GetItem(i)=b(i) Thenprint i& " is right"elseprint i& " is wrong" End If
Next
这篇关于UFT_基础14_动态数组重构excel,字典的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!