Vbscript 为什么我的DateDiff返回一个长的负数?
一般来说,对编码非常陌生,尤其是VB脚本 我试图启动一个动作的计时器,并在页面加载时结束它。然后我想知道这一行动花了多少秒(这里的目标是不到20秒) 当我运行时,它返回一个很长的负数-3733642190秒 这是密码Vbscript 为什么我的DateDiff返回一个长的负数?,vbscript,automation,Vbscript,Automation,一般来说,对编码非常陌生,尤其是VB脚本 我试图启动一个动作的计时器,并在页面加载时结束它。然后我想知道这一行动花了多少秒(这里的目标是不到20秒) 当我运行时,它返回一个很长的负数-3733642190秒 这是密码 'Choose the first record PbWindow("w_mainframe").PbWindow("w_cash_detail").PbDataWindow("dw_search_main").SelectCell "#1","Contract_Party_Nam
'Choose the first record
PbWindow("w_mainframe").PbWindow("w_cash_detail").PbDataWindow("dw_search_main").SelectCell "#1","Contract_Party_Name"
PbWindow("w_mainframe").PbWindow("w_cash_detail").PbDataWindow("dw_search_main").ActivateCell "#1","Contract_Party_Name"
'start the timer
startTime = Now()
'Wait while the page load - up to 60 seconds.
While Not(PbWindow("w_mainframe").PbWindow("w_cash_detail").Exist(1)) and DateDiff("s", startTime, Now) <=60
Wait(1)
Wend
'If page did load, move on and test that the time was less than 20 seconds.
If PbWindow("w_mainframe").PbWindow("w_cash_detail").Exist Then
Reporter.ReportEvent micPass, "Invoice Items Page", "Invoice Items page loads from ACD search results successfully"
'stop the clock.
endTime = Now()
End If
'Time Comparison
If ABS(DateDiff("s", startTime, endTime)) <=20 Then
Reporter.ReportEvent micPass, "ACD page opened in" & " " & DateDiff("s", startTime, endTime) & " " & "second(s)", "The ACD opened this invoice in twenty seconds or less."
else Reporter.ReportEvent micFail, "ACD page opened in" & " " & DateDiff("s", startTime, endTime) & " " & "second(s)", "The ACD took longer than twenty seconds to open a normal Invoice."
End IF
”选择第一条记录
PbWindow(“w#U大型机”).PbWindow(“w#U现金详细信息”).PbDataWindow(“dw#U搜索主机”)。选择单元格“#1”,“合同方名称”
PbWindow(“主机”).PbWindow(“现金详细信息”).PbDataWindow(“搜索主机”).ActivateCell“#1”,“合同方名称”
“启动计时器
startTime=Now()
'页面加载时等待-最多60秒。
虽然不是(PbWindow(“w_大型机”).PbWindow(“w_现金详细信息”).Exist(1))和DateDiff(“s”,startTime,Now)我将添加此作为答案,以便其他人可以看到原因和解决方案
如果设置了startTime
,但endTime
设置为Empty
,这将是预期的行为
修复方法是将其移到If
语句之外:
endTime = Now()
看看当你运行这个时会发生什么WScript.Echo DateDiff(“s”,现在为空)
这有帮助吗?我在尝试保存时遇到“预期语句结束”错误。我想我把它放错地方了?Reporter.ReportEvent micPass,“ACD页面在“&”&WScript.Echo DateDiff(“s”,现在为空)和“&”秒中打开,“ACD在二十秒或更短时间内打开了此发票。”您必须将其放在自己的行中才能工作,但我试图说明,endTime
是Empty
-如中所示,它永远不会被设置。因为它只在前面的If
语句中设置,所以我的假设是前面的If
语句返回false,而endTime
从未设置。试着把它从If
语句中移出。这似乎奏效了!谢谢