Jump to content
CaptainBeardsEyesBeard

Using @Error

Recommended Posts

CaptainBeardsEyesBeard

Hi I'm just trying to figure out error handling in Autoit 

I'm trying to learn error handling in Autoit and at the moment I'm having trouble with switching to the correct window however it is executing the Else statement not the If statement. 

I'll also point out it's not switching to the Solcase application

 

WinActivate("SolCase 7 - a LexisNexis Visualsfiles product") ; Focus Elite window
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Error", "Switching window")
 Else
    MsgBox($MB_SYSTEMMODAL, "Error", "blah blah")
    EndIf

Thanks

Edited by CaptainBeardsEyesBeard

Share this post


Link to post
Share on other sites
Jos

I guess you need:

$wHnd=WinActivate("SolCase 7 - a LexisNexis Visualsfiles product") ; Focus Elite window
If $wHnd Then
    MsgBox($MB_SYSTEMMODAL, "Found window", "Switching window")
Else
    MsgBox($MB_SYSTEMMODAL, "Error", "$wHnd is 0 so window not found")
EndIf

since the helpfile states:

Quote

Return Value

Success: the handle of the window.
Failure: 0 if window is not found or cannot be activated.

Remarks

You can use the WinActive() function to check if WinActivate() succeeded. If multiple windows match the criteria, the window that was most recently active is the one activated. WinActivate() works on minimized windows. However, a window that is "Always On Top" could still cover up a window you Activated.

After a successful activation @extended is set to 1 if the the window was already active, 2 if not.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
CaptainBeardsEyesBeard

Nice one thanks. 

 

I had read previously that the @error is used as a try/catch method in autoit. 

 

In what instance would I use @error? 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.