UFT_基础14_动态数组重构excel,字典

来源:互联网 发布:淘宝网棉拖鞋批发 编辑:程序博客网 时间:2024/06/06 19:26

字典 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个元素,值为2msgbox key(1)//根据key值获取字典中的数据value=objDic.Item("1")msgbox value----------//动态数组Dim Arr()For i = 1 To 3    ReDim preserve arr(i-1)    arr(i-1)=iNextmsgbox 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----------//excelFunction 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 =ArrEnd Function----------//调用函数excelb = 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 -1    If fromCity.GetItem(i)=b(i) Then        print i& " is right"    else        print i& " is wrong"        End IfNext
原创粉丝点击