johnmcloud Posted December 30, 2011 Posted December 30, 2011 (edited) Maybe is a stupid question, but i can't find a solution Func Basic() $Folder = GUICtrlRead($FileInput) If Not FileExists($Folder) Then MsgBox(16, "Error", "No folder") EndIf If FileExists(GUICtrlRead($FileInputCrypt) & "*.txt") Then MsgBox(16, "Errore", "Find txt folder") EndIf $Password=GUICtrlRead($UserInput) If $Password="" Then MsgBox(16,"Errore","No user input") EndIf $Path = GUICtrlRead($FileInput) $Folders= _FileListToArray($Path, '*', 1) $Folders[0] = "@echo off" & @CRLF $Pre = "C:\Test.exe" $Command = "-e -p" For $i = 1 to UBound($Folders) -1 $Success = $Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & $Password & " " & '"' & $Path & "\" & $Folders[$i] & '"', @TempDir, @SW_HIDE) Next If GUICtrlRead($Checkbox) = $GUI_CHECKED Then File_Delete() EndIf If $Success Then MsgBox(0,"Information","Success") EndIf EndFunc When i have error messages by MsgBox, i want simply stop to go ahead with the script, without exit. How i can do? N.B. If need i'll post all script, but i think i need a function, but i don't know which. Thanks Edited December 30, 2011 by johnmcloud
Moderators Melba23 Posted December 30, 2011 Moderators Posted December 30, 2011 johnmcloud,Use the Return function to end the function when you wish. I would also return a value so that the main script knows whether the function was successful or not: Func Basic() $Folder = GUICtrlRead($FileInput) If Not FileExists($Folder) Then MsgBox(16, "Error", "No folder") Return 0 ; End the function here and set the return value to 0 = Failure EndIf If FileExists(GUICtrlRead($FileInputCrypt) & "*.txt") Then MsgBox(16, "Errore", "Find txt folder") Return 0 ; End the function here and set the return value to 0 = Failure EndIf $Password = GUICtrlRead($UserInput) If $Password = "" Then MsgBox(16, "Errore", "No user input") Return 0 ; End the function here and set the return value to 0 = Failure EndIf $Path = GUICtrlRead($FileInput) $Folders = _FileListToArray($Path, '*', 1) $Folders[0] = "@echo off" & @CRLF $Pre = "C:\Test.exe" $Command = "-e -p" For $i = 1 To UBound($Folders) - 1 $Success = $Folders[$i] = RunWait(@ComSpec & " /c " & $Pre & " " & $Command & " " & $Password & " " & '"' & $Path & "\" & $Folders[$i] & '"', @TempDir, @SW_HIDE) Next If GUICtrlRead($Checkbox) = $GUI_CHECKED Then File_Delete() EndIf If $Success Then MsgBox(0, "Information", "Success") EndIf Return 1 ; The function ends here and sets the return value to 1 = Success EndFunc ;==>BasicNow you can call the function and check if it was a success - if it was not you could give the user a chance to enter correct data and rerun the function. You can also use Return SetError to give even more detail by using the @error and @extended macros. All clear? Please ask again if not. 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
johnmcloud Posted December 30, 2011 Author Posted December 30, 2011 (edited) Use the Return function to end the function when you wish. I would also return a value so that the main script knows whether the function was successful or not: Now you can call the function and check if it was a success - if it was not you could give the user a chance to enter correct data and rerun the function. You can also use Return SetError to give even more detail by using the @error and @extended macros. All clear? Please ask again if not. M23All clear, as always Thanks Melba. Edited December 30, 2011 by johnmcloud
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