yoinkster Posted February 9, 2009 Share Posted February 9, 2009 Hey guys, Another stupid question for you all! Hopefully I can make sense explaining it ... Basically I've got my program which goes through a database update process with a 3rd party application and it does everything fine apart from potential error catching. When an update is successfully completed a new child window comes up and at the minute all I do is sleep for a given time, test if the window exists and continue if it does and if not, it sleeps again for a bit. What I'd like to be able to say is something like "When %success window% exists do command1 command2 etc When %fail window% exists do command3 command4 etc" which is easy enough with an If instead of When as you can sleep and then check but I'd like to be able to do it without sleeping, can you like catch a window as it pops up and identify it somehow? Link to comment Share on other sites More sharing options...
James Posted February 9, 2009 Share Posted February 9, 2009 While WinExists("Window Name") ; Do code Wend Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
BrettF Posted February 9, 2009 Share Posted February 9, 2009 WinWait? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
yoinkster Posted February 9, 2009 Author Share Posted February 9, 2009 will that catch it as soon as the window exists? How would you put that into a custom function? If you had something like expandcollapse popupFunc doUpdate ; pre update commands While WinExists("success") ; Do code Wend While WinExists("fail") ; Do code Wend ; post update commands EndFuncoÝ÷ Û .ØÁ¨º{bÞ¡ûayhbíý²mç§r©ë^têð¢é]ÖÞÂí¯x,¢g)àÞ)jëh×6Func preUpdate ;pre update commands doUpdate() EndFunc Func doUpdate While WinExists("success") someBool = y ; Do code Wend While WinExists("fail") someBool = y ; Do code Wend postUpdate() EndFunc Func postUpdate if someBool then ; post update commands else doUpdate() EndFunc Link to comment Share on other sites More sharing options...
Manjish Posted February 9, 2009 Share Posted February 9, 2009 winwait will just pause the script till the window exists.. he wants to do something if the windows doesnt exist as well.. so if it never exists then the script will pause infinitely.. maybe putting a timeout will resolve this.. What say Brett? [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Manjish Posted February 9, 2009 Share Posted February 9, 2009 if WinWait("success","",3) Then ;do something Else ;do something EndIf [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
yoinkster Posted February 9, 2009 Author Share Posted February 9, 2009 That then gives rise to a static waiting time, sometimes the updates on the small databases will take 30seconds, others can take 5minutes. And clients with rubbish workstations might even take longer than that! So I'd like to get away from having a fixed waiting time if at all possible Link to comment Share on other sites More sharing options...
James Posted February 9, 2009 Share Posted February 9, 2009 Look at the Adlib functions. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
yoinkster Posted February 9, 2009 Author Share Posted February 9, 2009 (edited) Hmm, ok, how would that work? Does it pause the script while the adlib function is called? How do you tell it to stop adlibing to the function? Edited February 9, 2009 by yoinkster Link to comment Share on other sites More sharing options...
BrettF Posted February 9, 2009 Share Posted February 9, 2009 AdLibEnable AdLibDisable ... Cheers Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 9, 2009 Moderators Share Posted February 9, 2009 Just use WinWait(), the time is optional. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Manjish Posted February 9, 2009 Share Posted February 9, 2009 Just use WinWait(), the time is optional.that would be risky.. what if the window doesn't turn up.. this will pause the script forever.. adlib funcs are a good idea.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 9, 2009 Moderators Share Posted February 9, 2009 (edited) that would be risky.. what if the window doesn't turn up.. this will pause the script forever.. adlib funcs are a good idea..Then use the time functions .... it doesn't make any sense what so ever to use adlib functions when WinWait has a built in fall out already. Edit for pseudo code: If Not WinWait($h_wnd, $s_text, $i_max_timeout) Then MsgBox(16, "Error", "It failed") Else MsgBox(64, "Info", "Success") EndIf Edited February 9, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
yoinkster Posted February 9, 2009 Author Share Posted February 9, 2009 I still don't get it :) you do func blah() adlibenable("dave()", 1000) adlibdisable endfunc func dave() ; some commands endfunc would then do ... what ? it enables the adlibbing of dave but then disables it in the next line, do you need to put something in dave() to tell blah() to go on to the next line of the function? Link to comment Share on other sites More sharing options...
yoinkster Posted February 9, 2009 Author Share Posted February 9, 2009 In the end I did this, do you think it's a tidy enough solution? While 1 If %success% Then ; do stuffs ExitLoop ElseIf %fail% Then ; do other stuffs ExitLoop EndIf WEnd Link to comment Share on other sites More sharing options...
James Posted February 9, 2009 Share Posted February 9, 2009 Why do your variables tag a % at the end? Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
yoinkster Posted February 9, 2009 Author Share Posted February 9, 2009 oh thats just my notation sorry, in an attempt to differentiate between a variable ($), a program/function etc, it's just a label to indicate a psuedo result Link to comment Share on other sites More sharing options...
Richard Robertson Posted February 9, 2009 Share Posted February 9, 2009 You are trying to wait until either a success or a fail window shows up? expandcollapse popupDim $windows[] = ["success", "fail"] $window = _WinsWait($windows) Switch $window Case -1 MsgBox(0, "", "Timeout occured") ; This won't happen if you don't use the timeout Case 0 MsgBox(0, "", "Success window found") Case 1 MsgBox(0, "", "Fail window found") Case Else MsgBox(0, "", "Something went wrong") EndSwitch ; Returns the index of the first window found or -1 on timeout Func _WinsWait($arrayofwindows, $timeoutinmilliseconds = 0) Local $a If $timeoutinmilliseconds > 0 Then $timer = TimerInit() While TimerDiff($timer) < $timeoutinmilliseconds For $a = 0 To UBound($arrayofwindows) - 1 If WinExists($arrayofwindows[$a]) Then Return $a Next Sleep(100) WEnd Return -1 Else While True For $a = 0 To UBound($arrayofwindows) - 1 If WinExists($arrayofwindows[$a]) Then Return $a Next Sleep(100) WEnd EndIf EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now