|
本帖最后由 玩命格式化 于 2015-6-18 16:24 编辑
刚开始接触QTP,使用QTP调试读取、写入Excel函数时,发现将读取的Excel中的数值与windows计算器计算出来的数值进行比较时,结果显示两者是不同的,部分代码如下。请指教该如何设置,是不是该设置EXCEL中单元格的格式。
- SystemUtil.Run "calc.exe"
- Dim firstnum,secondnum,op,eque,path,sheet,row,col,text
- path="c:\test.xls"
- sheet="sheet1"
- For row=2 to GetRow (path,sheet)
- ''读取firstnumber并操作
- firstnum=ReadFromExcel (path,sheet,row,1)
- Set obutton=Description.Create
- For i=1 to len(firstnum)
- temp=mid(firstnum,i,1)
- If temp="." Then
- temp="\" &temp
- End If
- obutton("text").value=temp
- Window("计算器").WinButton(obutton).Click
- Next
- ''执行操作符op
- op=ReadFromExcel (path,sheet,row,2)
- Set obutton=Description.Create
- obutton("text").value="\"&op
- Window("计算器").WinButton(obutton).Click
- ''读取secondnum并操作
- secondnum=ReadFromExcel (path,sheet,row,3)
- Set obutton=Description.Create
- For i=1 to len(secondnum)
- temp=mid(secondnum,i,1)
- If temp="." Then
- temp="\" &temp
- End If
- obutton("text").value=temp
- Window("计算器").WinButton(obutton).Click
- Next
- ''进行计算
- Window("计算器").WinButton("=").Click
- '' 将计算结果写入actual
- Set actual=Window("计算器").WinEdit("Edit")
- x=actual.GetROProperty ("text")
- x=Rtrim (x)
- icount=len (x)-1
- If right (x ,1)="." Then
- x=left (x ,icount)
- End If
- WriteToExcel path,sheet,row,4,x
- print x
- ''向result写入测试结果p或f
- expected=ReadFromExcel (path,sheet,row,5)
- print expected
- If expected=x Then
- WriteToExcel path,sheet,row,6,"p"
- else
- WriteToExcel path,sheet,row,6,"f"
- End If
- Next
- Window("计算器").Close
复制代码 执行结果,在Excel中写入的计算结果是正确的,判断则表明两者不一致,写入了f。
|
|