我试图在线搜索但无法找到我需要的答案。这是我的任务和要求。我有2个函数,第一个检查条件并返回True和False。第二个启动计时器并定期检查第一个函数的结果,只有当返回值变为True时才退出。这是我的2个功能
' the 1st one checks if an item exists in JavaList
Public Function existInJavaList(ByRef javaList, ByVal itemName)
Dim itemcount, i, ret
ret = False
itemcount = javaList.GetROProperty("items count")
For i=0 to itemcount -1
If javaList.GetItem(i) = itemName Then
ret = True
Exit For
End If
Next
existInJavaList = ret
End Function
' the 2nd one checks the condition every 10 seconds and if the condition is True,
' it returns True. Otherwise, it times out after 120 seconds and returns False.
Function waitForCondition(ByVal condition)
Dim startTime, existFlag, accumulateTime
startTime = Timer()
existFlag = True
Do Until CBool(condition)
wait(10)
TimeElapsed = Timer()
If TimeElapsed - StartTime > 120 Then
existFlag = False
Exit Do
End If
Loop
waitForCondition = existFlag
End Function
如何将第1个函数作为第2个函数的参数传递,以便在第2个函数中每隔10秒调用一次?
欣赏任何建议。感谢。
答案 0 :(得分:0)
Function existInJavaList(ByRef javaList, ByVal itemName)
Dim itemcount, i, ret
ret = False
itemcount = javaList.GetROProperty("items count")
For i=0 to itemcount -1
If javaList.GetItem(i) = itemName Then
ret = True
Exit For
End If
Next
existInJavaList = ret
End Function
Function waitForCondition(ByVal condition)
Dim startTime, existFlag, accumulateTime
startTime = Timer()
existFlag = True
Do Until CBool(condition)
wait(10)
TimeElapsed = Timer()
If TimeElapsed - StartTime > 120 Then
existFlag = False
Exit Do
End If
Loop
waitForCondition = existFlag
End Function
答案 1 :(得分:0)
尝试这样的事情:
itemExists = waitForCondition(GetRef("existInJavaList"), Array(javaList, itemName))
Public Function existInJavaList(arrArgs)
Dim itemcount, i, ret, javaList, itemName
Set javaList = arrArgs(0)
itemName = arrArgs(1)
ret = False
itemcount = javaList.GetROProperty("items count")
For i = 0 to itemcount -1
If javaList.GetItem(i) = itemName Then
ret = True
Exit For
End If
Next
existInJavaList = ret
End Function
Function waitForCondition(condition, arrArgs)
Dim startTime, TimeElapsed, existFlag, accumulateTime
startTime = Timer()
existFlag = True
Do Until condition(arrArgs)
wait(10)
TimeElapsed = Timer()
If TimeElapsed - StartTime > 120 Then
existFlag = False
Exit Do
End If
Loop
waitForCondition = existFlag
End Function