AutoHotkey Community

It is currently May 27th, 2012, 2:47 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: November 24th, 2009, 4:59 pm 
Offline

Joined: May 15th, 2009, 6:26 pm
Posts: 12
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2009, 5:50 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2009, 3:41 am 
Offline

Joined: February 17th, 2008, 7:09 am
Posts: 536
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.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 25th, 2009, 3:54 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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
}
. . .

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2009, 3:56 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Debugging a Script


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn, XstatyK and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group