AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

best way to handle errors?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
scamper_22



Joined: 15 May 2009
Posts: 12

PostPosted: Tue Nov 24, 2009 3:59 pm    Post subject: best way to handle errors? Reply with quote

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
View user's profile Send private message
Carcophan



Joined: 24 Dec 2008
Posts: 768
Location: :noitacoL

PostPosted: Tue Nov 24, 2009 4:50 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
rtcvb32



Joined: 17 Feb 2008
Posts: 125

PostPosted: Wed Nov 25, 2009 2:41 am    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
sinkfaze



Joined: 18 Mar 2008
Posts: 2428

PostPosted: Wed Nov 25, 2009 2:54 am    Post subject: Re: best way to handle errors? Reply with quote

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
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 1770
Location: MN, USA

PostPosted: Wed Nov 25, 2009 2:56 am    Post subject: Reply with quote

Debugging a Script
_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group