Jump to content

Using @Error


Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...