Jump to content

Recommended Posts

Posted

I'm having a bit of trouble understanding how long @error and @extended hold their values. For example:

Main()

Func Main()

    _Test()

    Switch @error
        Case 1
            Switch @extended
                Case 2
                    ConsoleWrite("Y: " & @error & @CRLF)
                    ConsoleWrite("Y: " & @extended & @CRLF)
                Case Else
                    ConsoleWrite("N" & @CRLF)
            EndSwitch
        Case Else
            ConsoleWrite("N" & @CRLF)
    EndSwitch

    ConsoleWrite(@error & @CRLF)
    ConsoleWrite(@extended & @CRLF)

    ConsoleWrite(@error & @CRLF)
    ConsoleWrite(@extended & @CRLF)

    ConsoleWrite(@error & @CRLF)
    ConsoleWrite(@extended & @CRLF)

    Exit

EndFunc

Func _Test()
    SetError(1,2,3)
EndFunc

@error holds onto it's valve TWICE, and @extended ONCE

BUT:

Main()

Func Main()

    _Test()

    ConsoleWrite(@error & @CRLF)
    ConsoleWrite(@extended & @CRLF)

    ConsoleWrite(@error & @CRLF)
    ConsoleWrite(@extended & @CRLF)

    ConsoleWrite(@error & @CRLF)
    ConsoleWrite(@extended & @CRLF)

    Exit

EndFunc

Func _Test()
    SetError(1,2,3)
EndFunc

@error holds onto it's valve ONCE, and @extended NEVER
 

What statements don't affect the values of @error and @extended and which do? I don't see this documented anywhere.

 

Thanks!

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Posted

@rcmaehl

@error and @extended are set to 0 or different value every function call.

example

SetError(1, 2)

Local $error = @error
Local $extended = @extended

If $error or $extended Then
    ConsoleWrite("error: " & $error & @CRLF)
    ConsoleWrite("extended: " & $extended & @CRLF)
EndIf

ConsoleWrite("Now values after Func ConsoleWrite: " & @CRLF)
ConsoleWrite("error: " & @error & @CRLF)
ConsoleWrite("extended: " & @extended & @CRLF)

 

  • Moderators
Posted

rcmaehl,

Each call to a function (such as ConsoleWrite) will reset the values of @error and (usually) @extended to 0. So you need to read them immediately you return from the function:

Main()

Func Main()

    _Test()

    ; You can use variables to store the values
    $iError = @error
    $iExtended = @extended

    ; And try uncommenting this line and see what you get!!!!
    ;ConsoleWrite(@error & " - " & @extended & @CRLF) 

    ConsoleWrite(@error & @CRLF)    ; Reset @error on entering function - the parameter is parsed first so you still get the original @error
                                    ; @extended is usually reset to 0 too.....
    ConsoleWrite(@extended & @CRLF) ; .....so you will get 0 here when you try to read it

    ConsoleWrite(@error & @CRLF)    ; @error will now read 0
    ConsoleWrite(@extended & @CRLF) ; and @extended

    ConsoleWrite(@error & @CRLF)    ; @error will now read 0 here too
    ConsoleWrite(@extended & @CRLF) ; Guess what you get here!

    ConsoleWrite("But we still have the original @error stored: " & $iError & @CRLF)
    ConsoleWrite("And the original @extended: " & $iExtended & @CRLF)

    Exit

EndFunc   ;==>Main

Func _Test()
    SetError(1, 2, 3)
EndFunc   ;==>_Test

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

I'm pretty sure anytime you run any function it wipes @error out

Main()

Func Main()
    Local $val = _Test()
    ConsoleWrite($val & "." & @error & ":" & @extended & @CRLF)

    ConsoleWrite(@error & ":" & @extended & @CRLF)

    ConsoleWrite(@error & ":" & @extended & @CRLF)

    ConsoleWrite(@error & ":" & @extended & @CRLF)

    ConsoleWrite("Try 2" & @CRLF)

    $val = _Test()

    Switch @error
        Case 1
            Switch @extended
                Case 2
                    ConsoleWrite("Y: " & $val & "." & @error & ":" & @extended & @CRLF)
                Case Else
                    ConsoleWrite("N: " & $val & "." & @error & ":" & @extended & @CRLF)
            EndSwitch
        Case Else
            ConsoleWrite("N: " & $val & "." & @error & ":" & @extended & @CRLF)
    EndSwitch

    ConsoleWrite(@error & ":" & @extended & @CRLF)

    ConsoleWrite(@error & ":" & @extended & @CRLF)

    ConsoleWrite(@error & ":" & @extended & @CRLF)

EndFunc

Func _Test()
    Return SetError(1,2,3)
EndFunc

ConsoleWrite is a function as evidenced by ()

Edited by Bilgus
^Yeah What He SAID ^
Posted
7 minutes ago, Melba23 said:

rcmaehl,

Each call to a function (such as ConsoleWrite) will reset the values of @error and (usually) @extended to 0. So you need to read them immediately you return from the function

Okay, that's what I thought. Keywords and assignments are fine but functions aren't. Just wasn't documented anywhere and wanted to be safe.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

  • Moderators
Posted

rcmaehl,

Quote

Just wasn't documented anywhere

Final paragraph on this page of the Help file: https://www.autoitscript.com/autoit3/docs/function_notes.htm

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted
9 minutes ago, Melba23 said:

Final paragraph on this page of the Help file: https://www.autoitscript.com/autoit3/docs/function_notes.htm

oops :sweating:

Thanks

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

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
  • Recently Browsing   0 members

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