Jump to content
Sign in to follow this  
johnmcloud

[SOLVED] How to stop a script

Recommended Posts

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 by johnmcloud

Share this post


Link to post
Share on other sites

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   ;==>Basic

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. :D

All clear? Please ask again if not. ;)

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

 

Share this post


Link to post
Share on other sites

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. :D

All clear? Please ask again if not. ;)

M23

All clear, as always :)

Thanks Melba.

Edited by johnmcloud

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Similar Content

    • By Blitzkid
      Hello, i want to search several directories for files with the largest numbers behind them (Like "video123") . They dont have a datatype. But there are also files with longer names and datatypes in these folders (Like "video778.mp4"). Is it possible to filter the _FileListToArray Syntax from
      to smth. like
       
      Here is my Code
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <File.au3> $filedir = @ScriptDir & "\" _checkfile() Func _checkfile() ConsoleWrite("______________________" & @CRLF) Local $arr[3] = ["music", "picture", "video"] For $i = 0 To UBound($arr) - 1 Local $arrayfiles = _FileListToArray($filedir & $arr[$i], $arr[$i] & "*", 1) If @error = 1 Then ConsoleWrite($arr[$i] & "Error 1") EndIf If @error = 4 Then ConsoleWrite($arr[$i] & "Error 2") ;Exit EndIf $arrayfilter = _ArrayMax($arrayfiles, 0, 1) Global $stringfiles = StringReplace($arrayfilter, $arr[$i], "") ConsoleWrite($arrayfilter & @CRLF) Next EndFunc ;==>_checkfile  
    • By lee321987
      Sometimes when I call several MsgBox's they start popping up under other windows, which the requires ALT + TAB or click the taskbar icon.
      I just wanted to share this workaround:
      Just add a simple GUI in your program:
      #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 1, 1, 0, 0) GUISetState(@SW_SHOW) The GUI window size here is 1x1 so it will be nearly invisible, and at the top-left of your screen.
      It seems as long as that GUI is there all MsgBox's appear on top!
      I only tend to create several MsgBox's in a row when I'm actually writing and testing scripts, so the GUI being there is no big deal (I just remove/comment the GUI creation right before I build the .EXE).
      Have a great day!!!
       
       
    • By editcheck
      Hi, after years of use autoit i am tired to type all time:
      msgbox('','','Hi')
      So, wanna mod the function for set default values... or some more changes.
      where is the function?
      or there are another modes for debug messages that i do not knowed ? XD [just wanna like alert('text')]
      And is there any place for all integrates functions ?
      Thank. Sry my english =E
    • By Ackerz
      Hi guys,
      So I am trying to automate a task and this task has an input box with an already set character "9". 
      I have just decided that I don't really need the input as an option but it's good to leave however for this instance I would like it to run past this point automatically. I've tried numerous ways to try and automate the use of the "OK" button using ControlClick and various other options. I just can't seem to see where this point in the script is. Scoured the forums for anything similar but didn't have any luck finding anything. Sorry to be a pain and I hope someone can help, if I haven't explained in enough detail please don't hesitate to ask for more.
      Many thanks,
      Ackerz
       
      Local $len Local $n Local $buff Local $aMyDate $Len = InputBox("Test",$msgPrompt,"9") $len = StringStripWS($len,$STR_STRIPALL) ;Check that user has entered a vaild password length if not StringIsDigit($len) or $len = 0 Then MsgBox(48,"Error","Invaild Integer was entered" & @CRLF & "Program will now exit.") Exit EndIf ;This creates the random password. for $i = 1 to $Len ;Pick a random char between 1 and the pwsMask Length $n = int(random(1,StringLen($pwsMask))) ;Concat each char that has been picked out of pwsMask to $buff $buff = $Buff & StringMid($pwsmask,$n,1) Next  
    • By xtcislove
      Hello,
      as a start in Autoit i tried something i was missing since im using Autoit. 

      I build a custom MessageBox which has a large amount of custom options and which scales its size on the parameters you set. 

      Aviable Settings:
      -Title
      -Unlimited Buttons
      -Text Color (Buttons, Text)

      -Background Color (Msgbox, Buttons, Label) 

      -Button Timeout
      -Autoclose Timeout
      -Icon (Default, No Icon, Custom)

      -Label/ Button Style. 
      -Transparency

      I tried to keep this as close as i could to a Msgbox i was used too on my batch times.

      After i was ready i realised, @Melba23 probably build a way better msgbox which would have suit my needs enterly, anyway thanks to @Melba23 because i use his Stringsize UDF. 

       
       
      local $Message = _sMsgBox("Test", 6, "Continue?") if @extended <> -1 Then MsgBox(0, @extended, $Message&" Button pressed")  
      ScalingMessageBox.au3
×
×
  • Create New...