Jump to content

Recommended Posts

Posted

The Help file is very explicit about @error being reset to zero on entry to a User Function. But it is silent (as far as I can tell) about @error on Return from a Function. So I don't understand what is happening in this code.

Why does FuncR( ) return @error = 0?

Why does "SetError( @error )" in FuncS make it work the way I expected? As I read it, "SetError( @error )" says "Set @error equal to @error". Which would seem to be a NoOp.

Main()
Func Main()
    ConsoleWrite( "@AutoItVersion = " & @AutoItVersion & @CRLF )
    RegRead( "XXX", "" )
    ConsoleWrite( "RegRead. @error = " & @error & @CRLF )
    FuncR( )
    ConsoleWrite( "FuncR.   @error = " & @error & @CRLF )
    FuncS( )
    ConsoleWrite( "FuncS.   @error = " & @error & @CRLF )
EndFunc

Func FuncR( )
    RegRead( "XXX", "" )
EndFunc

Func FuncS( )
    RegRead( "XXX", "" )
    SetError( @error )
EndFunc

-- Output ---------------------------------------------------------------------
@AutoItVersion = 3.3.16.1
RegRead. @error = 2
FuncR.   @error = 0
FuncS.   @error = 2

 

Posted

so he has a different attitude

Main()
Func Main()
    ConsoleWrite( "@AutoItVersion = " & @AutoItVersion & @CRLF )
    RegRead( "XXX", "" )
    ConsoleWrite( "RegRead. @error = " & @error & @CRLF )

    FuncR( )
    FuncS( )

EndFunc

Func FuncR( )
    RegRead( "XXX", "" )
    ConsoleWrite( "FuncR.   @error = " & @error & @CRLF )
EndFunc

Func FuncS( )
    RegRead( "XXX", "" )
    SetError( @error )
    ConsoleWrite( "FuncS.   @error = " & @error & @CRLF )
EndFunc

 

I know that I know nothing

Posted

@AGlassman I seem to recall experiencing the same issue when I first started working on a UDF. I think this entry from the Func help file entry applies --

Quote

Using Return with SetError() allows @error and @extended values to be returned as well as a value.

@ioa747 Pretty sure your calls to ConsoleWrite within each function will wipe out the value of the @error codes.

Posted

@AGlassman, please do not rely on the engine to handle such things for you. if you need the function to return a specific @error value (or @extended, or return value) please put yourself in a habit to set it explicitly. it will save you a lot of trouble.

in more ancient programming languages, when you declared a variable, you had to initialize it to zero, or it might contain some random value. this i find still to be a solid advice.

and the help file does clearly state, "Unless SetError() is called, then @error will remain 0 when the function ends. This means that in order for @error to be set after a function, it must be explicitly set. "

 

 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Posted (edited)
58 minutes ago, Danp2 said:

calls to ConsoleWrite within each function will wipe out the value of the @error codes.

Recent AutoIt version preservs errors and extendent when you call ConsoleWrite

EDIT as far as I remember....

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
1 hour ago, AGlassman said:
Func FuncS( )
    RegRead( "XXX", "" )
    SetError( @error )
EndFunc

This is wrong usage ... of course if you wana return error from this function.

...

Return SetError(....

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
9 minutes ago, Danp2 said:

@AGlassman I seem to recall experiencing the same issue when I first started working on a UDF. I think this entry from the Func help file entry applies --

@ioa747 Pretty sure your calls to ConsoleWrite within each function will wipe out the value of the @error codes.

Danp2 - I'm not sure I understand how your Help file reference applies in this case. I am not concerned with @extended or the returned value. Only @error.

ioa747. It would seem that ConsoleWrite is NOT reseting @error. It would appear that @error only gets reset to zero after returning from FuncR.

Main()
Func Main()
    ConsoleWrite( "@AutoItVersion = " & @AutoItVersion & @CRLF )
    RegRead( "XXX", "" )
    ConsoleWrite( "RegRead.           @error = " & @error & @CRLF )

    FuncR( )
    ConsoleWrite( "FuncR Return.      @error = " & @error & @CRLF )

    FuncS( )
    ConsoleWrite( "FuncS Return.      @error = " & @error & @CRLF )

EndFunc

Func FuncR( )
    RegRead( "XXX", "" )
    ConsoleWrite( "FuncR 1st Write.   @error = " & @error & @CRLF )
    ConsoleWrite( "FuncR 2nd Write.   @error = " & @error & @CRLF )
EndFunc

Func FuncS( )
    RegRead( "XXX", "" )
    SetError( @error )
    ConsoleWrite( "FuncS.             @error = " & @error & @CRLF )
EndFunc

-- Output ---------------------------------------------------------------------
@AutoItVersion = 3.3.16.1
RegRead.           @error = 2
FuncR 1st Write.   @error = 2
FuncR 2nd Write.   @error = 2
FuncR Return.      @error = 0
FuncS.             @error = 2
FuncS Return.      @error = 0

 

Posted
Posted
10 minutes ago, Nine said:

Not anymore, see last update notes...

Maybe we've hit an edge case where it is still not working correctly. Here's the code I'm using to test --

Main()
Func Main()
    ConsoleWrite( "@AutoItVersion = " & @AutoItVersion & @CRLF )
    RegRead( "XXX", "" )
    ConsoleWrite( "RegRead. @error = " & @error & @CRLF )

    FuncR( )
    ;### Debug CONSOLE ↓↓↓
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @error = ' & @error & @CRLF & '>Error code: ' & @error & @CRLF)
    FuncS( )
    ;### Debug CONSOLE ↓↓↓
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @error = ' & @error & @CRLF & '>Error code: ' & @error & @CRLF)

EndFunc

Func FuncR( )
    RegRead( "XXX", "" )
    ConsoleWrite( "FuncR.   @error = " & @error & @CRLF )
EndFunc

Func FuncS( )
    RegRead( "XXX", "" )
    SetError( @error )
    ConsoleWrite( "FuncS.   @error = " & @error & @CRLF )
EndFunc

Here's the output when the ConsoleWrite is present in FuncS --

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\danpo\OneDrive\Documents\GitHub\WD Test\test3.au3" /UserParams    
+>17:03:16 Starting AutoIt3Wrapper (23.402.1150.2) from:SciTE.exe (5.3.8.0)  Keyboard:00000409  OS:WIN_11/2009  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\danpo\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\danpo\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.16.1)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\danpo\OneDrive\Documents\GitHub\WD Test\test3.au3
+>17:03:16 AU3Check ended. rc:0
>Running:(3.3.16.1):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\danpo\OneDrive\Documents\GitHub\WD Test\test3.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart. --> Press Ctrl+BREAK to Stop.
@AutoItVersion = 3.3.16.1
RegRead. @error = 2
FuncR.   @error = 2
@@ Debug(9) : @error = 0
>Error code: 0
FuncS.   @error = 2
@@ Debug(12) : @error = 0
>Error code: 0
+>17:03:16 AutoIt3 ended. rc:0
+>17:03:16 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.5162

This is the output when that line is removed --

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\danpo\OneDrive\Documents\GitHub\WD Test\test3.au3" /UserParams    
+>17:05:49 Starting AutoIt3Wrapper (23.402.1150.2) from:SciTE.exe (5.3.8.0)  Keyboard:00000409  OS:WIN_11/2009  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\danpo\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\danpo\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.16.1)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\danpo\OneDrive\Documents\GitHub\WD Test\test3.au3
+>17:05:49 AU3Check ended. rc:0
>Running:(3.3.16.1):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\danpo\OneDrive\Documents\GitHub\WD Test\test3.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart. --> Press Ctrl+BREAK to Stop.
@AutoItVersion = 3.3.16.1
RegRead. @error = 2
FuncR.   @error = 2
@@ Debug(9) : @error = 0
>Error code: 0
@@ Debug(12) : @error = 2
>Error code: 2
+>17:05:49 AutoIt3 ended. rc:0
+>17:05:49 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.6063

 

Posted
3 hours ago, Danp2 said:

Maybe we've hit an edge case where it [ConsoleWrite] is still not working correctly.

Danp2 - It does not appear to have anything to do with calling ConsoleWrite (see code below).

Inside FuncR @error is non-zero. But on return from the function it has been reset to zero.

Which I could accept as "That's just how it works. Return resets @error. Add it to the AutoIt Gotcha! list".

Except that doing a "SetError", instead of calling code that sets @error (see FuncT), seems to have some sort of side effect that makes the @error value "stick" on return.

Main()
Func Main()

    ConsoleWrite( "@AutoItVersion = " & @AutoItVersion & @CRLF )

    RegRead( "XXX", "" )
    If Not @error Then ConsoleWrite( "After RegRead.        @error is Zero" & @CRLF )

    FuncR( )
    If Not @error Then ConsoleWrite( "After FuncR Call.     @error is Zero" & @CRLF )

    FuncT( )
    If Not @error Then ConsoleWrite( "After FuncT Call.     @error is Zero" & @CRLF )

EndFunc

Func FuncR( )

    RegRead( "XXX", "" )
    If Not @error Then ConsoleWrite( "Before FuncR Return.  @error is Zero" & @CRLF )
    Return

EndFunc

Func FuncT( )

    SetError( 2 )
    If Not @error Then ConsoleWrite( "Before FuncT Return.  @error is Zero" & @CRLF )
    Return

EndFunc

---  Output ---------------------------------------------------------------------
@AutoItVersion = 3.3.16.1
After FuncR Call.     @error is Zero
+>21:01:35 AutoIt3.exe ended.rc:0

 

Posted
29 minutes ago, AGlassman said:

Danp2 - It does not appear to have anything to do with calling ConsoleWrite (see code below).

I disagree. Your code as posted doesn't call ConsoleWrite within the function because @error is always not zero. Try it with this modified version --

Main()
Func Main()

    ConsoleWrite( "@AutoItVersion = " & @AutoItVersion & @CRLF )

    RegRead( "XXX", "" )
    If Not @error Then ConsoleWrite( "After RegRead.        @error is Zero" & @CRLF )

    FuncR( )
    If Not @error Then ConsoleWrite( "After FuncR Call.     @error is Zero" & @CRLF )

    FuncT( )
    If Not @error Then ConsoleWrite( "After FuncT Call.     @error is Zero" & @CRLF )

EndFunc

Func FuncR( )

    RegRead( "XXX", "" )
    If @error Then ConsoleWrite( "Before FuncR Return.  @error is non-Zero" & @CRLF )
    Return

EndFunc

Func FuncT( )

    SetError( 2 )
    If @error Then ConsoleWrite( "Before FuncT Return.  @error is non-Zero" & @CRLF )
    Return

EndFunc

---  Output ---------------------------------------------------------------------
Before FuncR Return.  @error is non-Zero
After FuncR Call.     @error is Zero
Before FuncT Return.  @error is non-Zero
After FuncT Call.     @error is Zero

 

Posted

As to your statement:

13 hours ago, AGlassman said:

Why does "SetError( @error )" in FuncS make it work the way I expected? As I read it, "SetError( @error )" says "Set @error equal to @error". Which would seem to be a NoOp.

Here I wrote:

12 hours ago, mLipok said:

This is wrong usage ... of course if you wana return error from this function.

...

Return SetError(....

And this is what I mean:

Main()
Func Main()
    ConsoleWrite("@AutoItVersion = " & @AutoItVersion & @CRLF)
    RegRead("XXX", "")
    ConsoleWrite("RegRead. @error = " & @error & @CRLF)
    FuncR()
    ConsoleWrite("FuncR.   @error = " & @error & @CRLF)
    FuncS()
    ConsoleWrite("FuncS.   @error = " & @error & @CRLF)
    FuncS2()
    ConsoleWrite("FuncS2.   @error = " & @error & @CRLF)
    FuncS3()
    ConsoleWrite("FuncS3.   @error = " & @error & @CRLF)
    FuncS4_1()
    ConsoleWrite("FuncS4_1.   @error = " & @error & @CRLF)
    FuncS4_2()
    ConsoleWrite("FuncS4_2.   @error = " & @error & @CRLF)
    FuncS5_1()
    ConsoleWrite("FuncS5_1.   @error = " & @error & @CRLF)
    FuncS5_2()
    ConsoleWrite("FuncS5_2.   @error = " & @error & @CRLF)
EndFunc   ;==>Main

Func FuncR()
    RegRead("XXX", "")
EndFunc   ;==>FuncR

Func FuncS()
    RegRead("XXX", "")
    SetError(@error)
EndFunc   ;==>FuncS

Func FuncS2()
    RegRead("XXX", "")
    SetError(@error)
EndFunc   ;==>Func2

Func FuncS3()
    RegRead("XXX", "")
    SetError(@error)
    Return
EndFunc   ;==>FuncS3

Func FuncS4_1()
    RegRead("XXX", "")
    ConsoleWrite(@CRLF)
    Return
EndFunc   ;==>FuncS3

Func FuncS4_2()
    RegRead("XXX", "")
    SetError(@error)
    ConsoleWrite(@CRLF)
    Return
EndFunc   ;==>FuncS3

Func FuncS5_1()
    RegRead("XXX", "")
    ConsoleWrite(@CRLF)
    Return SetError(@error)
EndFunc   ;==>FuncS3

Func FuncS5_2()
    RegRead("XXX", "")
    SetError(@error)
    ConsoleWrite(@CRLF)
    Return SetError(@error)
EndFunc   ;==>FuncS3

In my understanding only FuncS3, FuncS5_1, FuncS5_2 should be correct way how to return desired error from function.

 

But I also wonder why FuncS2 and FuncS3 returns errors in relation to the fact that FuncS4_1 and FuncS4_2 does not retur error

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

Hope @jpm will take a look here soon.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

  • Developers
Posted (edited)
9 hours ago, Nine said:

Agree, very edgy.  And also very ugly.  :ermm:

But we may be able to call it a bug... 

Looks good to me...   @error contains the last func's value.

Edited by 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.
  :)

  • Developers
Posted (edited)
1 hour ago, mLipok said:

ut I also wonder why FuncS2 and FuncS3 returns errors in relation to the fact that FuncS4_1 and FuncS4_2 does not retur error

again...  all making sense! 

FuncS4_1 & 2 return the @error value of consolewrite, so logically 0 

Edited by 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.
  :)

Posted

@Jos I think they refer to what help file states for ConsoleWrite().

Quote

The @error and @extended are not set on return leaving them as they were before calling. Usefull when debugging with the SciTE debugging output.

If I understand right ConsoleWrite() should not affect @error macro.

Posted

..early morning for me but this looks like a collective brain fog. The ConsoleWrite() behaves as:

Func ConsoleWrite_BehavesAs($data, $iError = @error, $iExtended = @extended)
    Local $iLength = ConsoleWrite($data)
    Return SetError($iError, $iExtended, $iLength)
EndFunc

I don't see anything wrong or confusing on any of the above posts. I don't find anything perplexing in the OP question.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

@Jos I was refering to the same what @Andreik mention (thanks).

@argumentum yes it should behaves like you said 'The ConsoleWrite() behaves as:'

but why it is not working this way in  FuncS4_1 and FuncS4_2  ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)
11 minutes ago, mLipok said:

but why it is not working this way in  FuncS4_1 and FuncS4_2  ?

to better illustrate the problem:

;~ https://www.autoitscript.com/forum/topic/211040-error-lost-on-return-without-seterror/#comment-1526182

Main()
Func Main()
    ConsoleWrite("@AutoItVersion = " & @AutoItVersion & @CRLF)
    RegRead("XXX", "")
    ConsoleWrite("RegRead. @error = " & @error & @CRLF)
    FuncR()
    ConsoleWrite("FuncR.   @error = " & @error & @CRLF)
    FuncS()
    ConsoleWrite("FuncS.   @error = " & @error & @CRLF)
    FuncS2()
    ConsoleWrite("FuncS2.   @error = " & @error & @CRLF)
    FuncS3()
    ConsoleWrite("FuncS3.   @error = " & @error & @CRLF)
    FuncS4_1()
    ConsoleWrite("FuncS4_1.   @error = " & @error & @CRLF)
    FuncS4_2()
    ConsoleWrite("FuncS4_2.   @error = " & @error & @CRLF)
    FuncS5_1()
    ConsoleWrite("FuncS5_1.   @error = " & @error & @CRLF)
    FuncS5_2()
    ConsoleWrite("FuncS5_2.   @error = " & @error & @CRLF)
EndFunc   ;==>Main

Func FuncR()
    RegRead("XXX", "")
EndFunc   ;==>FuncR

Func FuncS()
    RegRead("XXX", "")
    SetError(@error)
EndFunc   ;==>FuncS

Func FuncS2()
    RegRead("XXX", "")
    SetError(@error)
EndFunc   ;==>Func2

Func FuncS3()
    RegRead("XXX", "")
    SetError(@error)
    Return
EndFunc   ;==>FuncS3

Func FuncS4_1()
    RegRead("XXX", "")
    ConsoleWrite(@CRLF)
    ConsoleWrite('FuncS4_1: inner check: ' & @error & @CRLF)
    ConsoleWrite('FuncS4_1: inner check: ' & @error & @CRLF)
    ConsoleWrite('FuncS4_1: inner check: ' & @error & @CRLF)
    Return
EndFunc   ;==>FuncS3

Func FuncS4_2()
    RegRead("XXX", "")
    SetError(@error)
    ConsoleWrite(@CRLF)
    ConsoleWrite('FuncS4_2: inner check: ' & @error & @CRLF)
    ConsoleWrite('FuncS4_2: inner check: ' & @error & @CRLF)
    ConsoleWrite('FuncS4_2: inner check: ' & @error & @CRLF)
    Return
EndFunc   ;==>FuncS3

Func FuncS5_1()
    RegRead("XXX", "")
    ConsoleWrite(@CRLF)
    Return SetError(@error)
EndFunc   ;==>FuncS3

Func FuncS5_2()
    RegRead("XXX", "")
    SetError(@error)
    ConsoleWrite(@CRLF)
    Return SetError(@error)
EndFunc   ;==>FuncS3

 

so FuncS3 return error

Func FuncS3()
    RegRead("XXX", "")
    SetError(@error)
    Return
EndFunc   ;==>FuncS3

and FuncS4_2 does not return error

Func FuncS4_2()
    RegRead("XXX", "")
    SetError(@error)
    ConsoleWrite(@CRLF)
    ConsoleWrite('FuncS4_2: inner check: ' & @error & @CRLF)
    ConsoleWrite('FuncS4_2: inner check: ' & @error & @CRLF)
    ConsoleWrite('FuncS4_2: inner check: ' & @error & @CRLF)
    Return
EndFunc   ;==>FuncS3

Please note that each ConsoleWrite retains errors:

Quote

The @error and @extended are not set on return leaving them as they were before calling.

 

EDIT:
So in some sense they are actually retained I mean, until you want to return from the function.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

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
×
×
  • Create New...