我想在我的QTP腳本中使用的DoEvents - 但得到的錯誤 - 類型不匹配:調用DoEvents'如何在QTP 11中使用DoEvents?
下面是我的腳本:
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
Const SYNCHRONIZE = &H100000
Extern.Declare micHwnd, "CloseHandle", "kernel32", "CloseHandle", micLong
Extern.Declare micHwnd, "WaitForSingleObject", "kernel32", "WaitForSingleObject", micLong, micLong
Extern.Declare micHwnd, "OpenProcess", "kernel32", "OpenProcess", micLong, micLong, micLong
Extern.Declare micHwnd, "GetExitCodeProcess", "kernel32", "GetExitCodeProcess", micLong, micLong
Public Function Run_XML(exeStr, ByVal logFile)
Dim pid, ExitEvent
Dim lineStr
Dim okFlg
Dim hProcess
Dim wait_time
wait_time = input_details.Items()(19)
xmlCount = "0"
okFlg = 0
Dim SystemProcess
Set SystemProcess = DotNetFactory.CreateInstance("System.Diagnostics.Process")
Dim processStartInfo
Set processStartInfo = DotNetFactory.CreateInstance("System.Diagnostics.ProcessStartInfo")
processStartInfo.UseShellExecute = false
processStartInfo.FileName = "plink.exe"
processStartInfo.Arguments = Chr(34) + " -load " + Chr(34) + session_name + Chr(34) + " -l " + Chr(34) + login_id + Chr(34) + " -pw " + Chr(34) + pwd + Chr(34) + " -m " + Chr(34) + cmd_dir + "commands.txt" + Chr(34) + " >> " + Chr(34) + log_dir & log_filename + Chr(34)
Dim myProcess
Set myProcess = SystemProcess.Start(processStartInfo)
pid = myProcess.Id
hProcess = Extern.OpenProcess(SYNCHRONIZE, False, pid)
ExitEvent = Extern.WaitForSingleObject(hProcess, (wait_time + 5) * 1000)
Do
Extern.GetExitCodeProcess hProcess, ExitEvent
DoEvents
Loop While ExitEvent = STILL_ACTIVE
Extern.CloseHandle(hProcess)
End Function
能否請你建議如果DOEVENTS是有效的QTP與否?如果沒有,那麼使用相同的其他方法或任何其他方法?
是否有任何其他替代'DoEvents'?我正在使用它來等待Unix批處理命令等待特定的輸出,然後打破循環進行進一步處理。有什麼,你可以幫助/建議可以做? – Krishna
那麼你現在的代碼是不是沒有'DoEvents',即'Loop While ExitEvent = STILL_ACTIVE'?還有'STILL_ACTIVE'在您的代碼中的某處定義?如果不是,那麼循環將不會工作,因爲STILL_ACTIVE被當作變量處理,因此值將爲'Null'。它應該是一個字符串? –
另外,您不應該需要DoEvents才能等待控制檯應用程序完成其任務。 –