| View previous topic :: View next topic |
| Author |
Message |
scamper_22
Joined: 15 May 2009 Posts: 12
|
Posted: Tue Nov 24, 2009 3:59 pm Post subject: best way to handle errors? |
|
|
Hi all,
just wondering what is the recommended way to handle errors.
In my case, I am using autohotkey to press some buttons and set some text of some controls. I ran into some issues where it takes a window some time to come up so when it executed the line, the control wasn't created yet. I temporarily just added in some sleeps.
Sleep(5000)
ControlClick...
Sleep(2000)
ControlSetText...
I'd rather have something a bit more concrete than the Sleeps.
Would you recommend testing the ErrorLevel after each Control command and then retrying it if needed.
Alternatively, I could test to see if a control exists first and then try the command.
Recommendations?
I'm leaning towards checking the error level myself. |
|
| Back to top |
|
 |
Carcophan
Joined: 24 Dec 2008 Posts: 768 Location: :noitacoL
|
Posted: Tue Nov 24, 2009 4:50 pm Post subject: |
|
|
MsgBox and ToolTip are the universal 'error checkers'. If used correctly (in the right places or with vaiables) they are magical.
Instead of a 'sleep' put in 'MsgBox, This is the first msgbox for testing reasons', if the box even comes up, you can assume the script has gotten to that point. And will continue until it reaches box 2 or 3 or 10. The msgboxs also can output variable information, so if you change values, you can verify everything is correct from step to step to step. _________________ "Unfortunately a "COM for Dummies" book would be a little like "Neurosurgery for Dummies," in the end you're just gonna have to learn" ~Tank |
|
| Back to top |
|
 |
rtcvb32
Joined: 17 Feb 2008 Posts: 125
|
Posted: Wed Nov 25, 2009 2:41 am Post subject: |
|
|
On top of that, use the documentation to your advantage. If it has errorlevel information or modification, use it for debugging as well as to make appropriate actions. You might start with simple error handling, but as specific errors pop up you'd add to it to handle more complex or common possibilities. Example:
| Code: |
FileReadLine, OutputVar, Filename, 1
If ErrorLevel {
msgbox i can't access the file.
return
}
;no errors, so outputvar HAS to have it's value.
|
|
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 2428
|
Posted: Wed Nov 25, 2009 2:54 am Post subject: Re: best way to handle errors? |
|
|
| scamper_22 wrote: | | ...I am using autohotkey to press some buttons and set some text of some controls...I could test to see if a control exists first and then try the command. |
Yes, you could...
| Code: | WinWait, << some window title >>
Loop {
ControlGet, v, Visible, , << some control >>, << some window title >> ; check state of some control in the window to see if it is visible
if !ErrorLevel ; expression, if Errorlevel is empty or zero (success)
break
Sleep 100 ; small delay before next loop iteration if failure
}
. . . |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 1770 Location: MN, USA
|
|
| Back to top |
|
 |
|