rcmaehl Posted March 2, 2018 Share Posted March 2, 2018 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 WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
Ascer Posted March 2, 2018 Share Posted March 2, 2018 @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) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 2, 2018 Moderators Share Posted March 2, 2018 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Bilgus Posted March 2, 2018 Share Posted March 2, 2018 (edited) I'm pretty sure anytime you run any function it wipes @error out expandcollapse popupMain() 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 March 2, 2018 by Bilgus ^Yeah What He SAID ^ Link to comment Share on other sites More sharing options...
rcmaehl Posted March 2, 2018 Author Share Posted March 2, 2018 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 WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 2, 2018 Moderators Share Posted March 2, 2018 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 rcmaehl 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rcmaehl Posted March 2, 2018 Author Share Posted March 2, 2018 9 minutes ago, Melba23 said: Final paragraph on this page of the Help file: https://www.autoitscript.com/autoit3/docs/function_notes.htm oops 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 WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now