Jump to content

Managing the error flag property in AutoItX?


daluu
 Share

Recommended Posts

AutoIt script has an @error macro/flag that gets set when some functions are called that fail. And one can check that flag's value after function call to see if it failed or not.

In AutoItX, the help file shows oAutoIt.error() or in some language's COM interface just oAutoIt.error w/o the parenthesis. I know that works.

But I was just recently wondering, how do you reset that flag if it doesn't auto-reset once you check the flag and continue onwards to other commands in your program/application and/or ignore the failure.

In the AutoIt script function reference, I see SetError() function:

https://www.autoitscript.com/autoit3/docs/functions/SetError.htm

just skimming over the AutoItX help file, I didn't notice an equivalent to SetError, unless I overlooked some section. So is there an equivalent to set/reset @error in AutoItX?

Or is it simply something like

oAutoIt.error(0) or oAutoIt.error = 0

Can someone clarify?

Link to comment
Share on other sites

Hmm...105 views, but no comments on behavior? I guess no AutoItX user ever had to worry about @error being reset for subsequent commands.

Guess I'll have to try and experiment sometime and then post my findings here.

Link to comment
Share on other sites

I'Ve never used AutoItX but I think doing a quick test is the easiest method to answer this question.

I would start with

oAutoIt.error = 0

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 weeks later...

Well, it looks like neither oAutoIt.error = 0 nor oAutoIt.error(0) work.

Logically, off the top of my head, I don't know of any other syntax one would normally use to reset the flag in AutoItX. I hope that's not a limitation the developers left out of AutoItX compared to AutoIt. If you can't reset the flag, then what's the point of the flag, in the cases where the user wants to do exception/error handling of "I don't care if there's a (benign) error, continue with next AutoIt command I'm about to run". Which one can typically do in programming languages & in Selenium by catching Selenium exceptions and ignoring them. But here, the flag stays set unlike Selenium exceptions once caught. I need to reset that flag.

FYI, I tested in both Python and VBScript for resetting the flag. Since VBScript is usually default for dealing with COM, even the AutoItX examples are in VBScript, I'll post my test snippet:

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
WScript.Echo oAutoIt.error 'should be 0
oAutoIt.ControlGetText "[active]","","[ID:33]"
WScript.Echo oAutoIt.error 'should be 1
If oAutoIt.error = 1 Then
    WScript.Echo "trying to reset error flag"
    oAutoIt.error = 0
    oAutoIt.error(0)
End If
WScript.Echo oAutoIt.error 'should be 0
WScript.Quit

You get output like this:

0
1
trying to reset error flag
c:\Temp\auerr.vbs(7, 2) Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment: 'oAutoIt.error'
c:\Temp\auerr.vbs(8, 2) Microsoft VBScript runtime error: Object doesn't support this property or method: 'oAutoIt.error'

 

It appears the damn flag is read only. How to write to it?

 

Edited by daluu
Link to comment
Share on other sites

There is a function: SetError. But I'm not sure it is available with AutoItX.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I know that function is in AutoIt, didn't see mention of it in AutoItX. Gave it a try with oAutoIt.SetError(0) and oAutoIt.SetError 0, gave similar errors. Guess that's not available under AutoItX.

But I saw the remark under SetError function: https://www.autoitscript.com/autoit3/docs/functions/SetError.htm

Hopefully that means that although the flag is set when there is error when next function is called, it gets reset to zero automatically, so that when you check the flag again, it is with respect to the last function called. Wish the AutoIt team at least updated the AutoItX help doc to mention that behavior for the error property as all that is noted is:

"Status of the error flag (equivalent to the @error macro in AutoIt v3)"

that's too basic. Do I have to consult the main AutoIt documentation to correlate everything else about the macro flag, sigh.

Link to comment
Share on other sites

Wouldn't you use something like SetLastError to set the error condition? And then use GetLastError to read it?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 2 weeks later...

Wouldn't you use something like SetLastError to set the error condition? And then use GetLastError to read it?

 

Well, the question of this thread was about checking the AutoIt error flag, that is set by AutoIt, and then resetting later (but sounds like AutoIt will auto-reset so that be ok, something I overlooked before). I don't know if but doubt SetLastError will modify AutoIt's error flag. Or has someone actually tried that out? By the way, those are C/C++ functions of win32 API, I don't know how that translates to COM. This thread was in reference to COM.

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...