Marcel2304 Posted February 11, 2021 Share Posted February 11, 2021 Hello, i have a quick and simple question. Is someting like this possible : If @error = 00 Then MsgBox(0,"test", "00 : " ) ElseIf @error = 230 Then MsgBox(0 ,"test","230 : ") EndIf Because i need to use the errorcode for moving on in my script. Thank you ! Link to comment Share on other sites More sharing options...
Nine Posted February 11, 2021 Share Posted February 11, 2021 Switch @error Case 0 ;do something here Case 230 ;do something else EndSwitch JockoDundee and Marcel2304 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Marcel2304 Posted February 12, 2021 Author Share Posted February 12, 2021 For errorcode 00 it is working. But for errorcode 230 not. It only shows me the msg box for case 0 and not 230 FileChangeDir("C:\Program Files\SEH Computertechnik GmbH\SEH UTN Manager") RunWait(@ComSpec & " /c " & "utnm.exe") Global $test = RunWait(@ComSpec & " /c " & 'utnm /c "activate xxxxxx 11" /k "BAUMANAGER"') MsgBox(0,"test", "Error : " & $test & @error) Switch @error Case 230 MsgBox(0,"Funkt", "23 : ") Case 00 MsgBox(0,"Funkt", "00 : ") EndSwitch Link to comment Share on other sites More sharing options...
pixelsearch Posted February 12, 2021 Share Posted February 12, 2021 In all scripts, the best way to avoid all this headache is to transfer @error in a variable, immediately after the line you want to test if it succeeded or not, for example : Global $test = RunWait(...) $iKeep_error = @error ; now you can check $iKeep_error wherever you like Musashi 1 Link to comment Share on other sites More sharing options...
jguinch Posted February 12, 2021 Share Posted February 12, 2021 (edited) @error is set by the last executed function. In you case, @error is set to 0 by MsgBox. Remove the MsgBox line after the RunWait function : RunWait(@ComSpec & " /c " & "utnm.exe") Global $test = RunWait(@ComSpec & " /c " & 'utnm /c "activate xxxxxx 11" /k "BAUMANAGER"') ; MsgBox(0,"test", "Error : " & $test & @error) Switch @error Case 230 MsgBox(0,"Funkt", "23 : ") Case 0 MsgBox(0,"Funkt", "00 : ") EndSwitch edit : in the same time with pixelsearch 😀 Edited February 12, 2021 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Marcel2304 Posted February 12, 2021 Author Share Posted February 12, 2021 It is only using case 00 and not 230. I am really new to this. So i changed the order of the Case and the script is always using case 2 ( case 0 ) no matter which errorcode is in it. Link to comment Share on other sites More sharing options...
Musashi Posted February 12, 2021 Share Posted February 12, 2021 5 minutes ago, pixelsearch said: In all scripts, the best way to avoid all this headache is to transfer @error in a variable, immediately after the line you want to test if it succeeded or not, for example : 4 minutes ago, jguinch said: @error is set by the last executed function. @Marcel2304 : These tips are really important. Even if a function like e.g. ConsoleWrite does not provide an error code (according to the help), @error will be reseted. Example : ; 1 : FileRead(@ScriptDir & "\blabla.txt") ; <-- a file, that does not exist ConsoleWrite("Error = " & @error & @CRLF & @CRLF) ; <-- Error = 1 ; 2 : FileRead(@ScriptDir & "\blabla.txt") ; <-- a file, that does not exist ConsoleWrite("Output :" & @CRLF) ConsoleWrite("Error = " & @error & @CRLF & @CRLF) ; <-- Error = 0 ; 3 : save @error in a var (mentioned by @pixelsearch): Local $iError FileRead(@ScriptDir & "\blabla.txt") ; <-- a file, that does not exist $iError = @error ConsoleWrite("Output :" & @CRLF) ConsoleWrite("Error = " & $iError & @CRLF) ; <-- Error = 1 pixelsearch 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Marcel2304 Posted February 12, 2021 Author Share Posted February 12, 2021 I get that but what i don't unterstand is why only case 0 is triggerd even when its case 230. Link to comment Share on other sites More sharing options...
pixelsearch Posted February 12, 2021 Share Posted February 12, 2021 (edited) Because you (probably) got a line that resets @error to 0, after your last RunWait and before the Switch line. Could you please tell us what happens if you script it like this and what is written in the Console Window ? FileChangeDir("C:\Program Files\SEH Computertechnik GmbH\SEH UTN Manager") RunWait(@ComSpec & " /c " & "utnm.exe") Global $test = RunWait(@ComSpec & " /c " & 'utnm /c "activate xxxxxx 11" /k "BAUMANAGER"') Local $iKeep_error = @error ; to be placed here, immediately after RunWait() line ConsoleWrite("$iKeep_error = " & $iKeep_error & @CRLF) MsgBox(0, "Result", "Test = " & $test & " Error = " & $iKeep_error) Switch $iKeep_error Case 230 MsgBox(0,"Funkt", "230 : ") Case 0 MsgBox(0,"Funkt", "0 : ") Case Else MsgBox(0,"Funkt", $iKeep_error) EndSwitch Edited February 12, 2021 by pixelsearch Added a Case Else, in case of... Link to comment Share on other sites More sharing options...
pixelsearch Posted February 12, 2021 Share Posted February 12, 2021 Something else read in the help file, topic RunWait : Return Value Success: the exit code of the program that was run. Failure: sets the @error flag to non-zero. So what is this 230 you mention ? If 230 is the correct return value you're expecting, then it has nothing to do with @error, which will be 0 if RunWait succeeded (returning 230) Link to comment Share on other sites More sharing options...
Musashi Posted February 12, 2021 Share Posted February 12, 2021 (edited) 29 minutes ago, Marcel2304 said: ... but what i don't unterstand is why only case 0 is triggerd even when its case 230. Probably because the error code 230 gets reseted to 0, as @pixelsearch already suspected. Test : _SimulateError() Local $iError = @error Switch $iError Case 00 ConsoleWrite("Error = " & $iError & @CRLF) Case 230 ConsoleWrite("Error = " & $iError & @CRLF) Case Else ConsoleWrite("something else" & @CRLF) EndSwitch Func _SimulateError() SetError(230) ; <-- set a value for @error, e.g. 00, 230 etc. EndFunc ;==>_SimulateError EDIT : I see, that @pixelsearch just pointed out the difference between @error and return value . Edited February 12, 2021 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." 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