Jump to content

Exit Function...but not script!


Go to solution Solved by argumentum,

Recommended Posts

Posted (edited)

Good day,

I have the following script:

; -----------------------------------------------
#include <array.au3>
#include <AutoItConstants.au3>
#inaclude <file.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
ListBackupFolders1()
; -----------------------------------------------
Func ListBackupFolders1()
    Local $sBackupFolderPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets"
    ; -----------------
    Local $ArrayFolders = _FileListToArrayRec($sBackupFolderPath, "*", $FLTAR_FOLDERS)
    ; -----------------
    Local $verify = MsgBox(68, "Notice!", "List the backup folders?!")
    ; -----------------------------------------------
    Select
        Case $verify = 6
            _ArrayDisplay($ArrayFolders, "Folder Listing", Default, 64)
        Case $verify = 7
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled. Exiting!", 1)
            Exit
    EndSelect
    ; -----------------------------------------------
    EnterSoundFolderName1()
EndFunc   ;==>ListBackupFolders1
; -----------------------------------------------
Func EnterSoundFolderName1()
    Local $sRootPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets\"
    Local $sSoundsFolderName = ""
    ; -----------------------------------------------
    While $sSoundsFolderName = ""
        $sSoundsFolderName = InputBox("NOTICE!", "Enter the Sounds Folder Name...", "", "", 150, 130)
        ; -----------------
        If @error Then
            MsgBox($MB_ICONWARNING, "Notice!", "The operation was cancelled. Exiting!")
            Exit
        Else
            Local $sBackupPath = DirCreate($sRootPath & $sSoundsFolderName)
            $sBackupPath = $sRootPath & $sSoundsFolderName
            DoesFolderExist($sBackupPath)
        EndIf
    WEnd
EndFunc   ;==>EnterSoundFolderName1
; -----------------------------------------------
Func DoesFolderExist($sBackupPath)
    Local $sDoesFolderExist = FileExists($sBackupPath)
    ; -----------------------------------------------
    If $sDoesFolderExist Then
        BackupSoundData($sBackupPath)
    Else
        CreateBackupFolder($sBackupPath)
    EndIf
EndFunc   ;==>DoesFolderExist
; -----------------------------------------------
Func CreateBackupFolder($sBackupPath)
    Local $iStart = 2, $iEnd = 1
    Local $sSrcPath[$iStart] = [$iEnd]
    $sSrcPath[1] = $sBackupPath
    ; -----------------
    Local $sMessage = "Create Backup Folder..." & @CRLF & @CRLF, $iWidth = 450, $iHeight = 135
    Local $iOpt = 5, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    ; -----------------------------------------------
    For $i = 1 To $sSrcPath[0]
        Local $sResult = DirCreate($sSrcPath[$i])
        $sBackupPath = $sSrcPath[$i]
        ; -----------------------------------------------
        Switch $sResult
            Case 0
                $sResult = "The Backup Folder DOES NOT exist!"
            Case 1
                $sResult = "The Backup Folder WAS created successfully!"
        EndSwitch
        ; -----------------------------------------------
        $sMessage &= $sResult & @CRLF
    Next
    ; -----------------------------------------------
    $sMessage &= @CRLF & "Creating Backup Folder is now completed..." & @CRLF
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
    ; -----------------------------------------------
    BackupSoundData($sBackupPath)
EndFunc   ;==>CreateBackupFolder
; -----------------------------------------------
Func BackupSoundData($sBackupPath)
    Local $iStart = 2, $iEnd = 1
    Local $sSrcPath[$iStart] = [$iEnd]
    $sSrcPath[1] = "E:\Text\Native Instruments\Guitar Rig 5\Sounds\*.ngrr"
    ; -----------------
    Local $sDstPath[$iStart] = [$iEnd]
    $sDstPath[1] = $sBackupPath
    ; -----------------
    Local $sMessage = "Backup All Sound File data..." & @CRLF & @CRLF, $iWidth = 450, $iHeight = 135
    Local $iOpt = 5, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    ; -----------------------------------------------
    For $i = 1 To $sSrcPath[0]
        Local $sResult = FileCopy($sSrcPath[$i], $sDstPath[$i], $FC_OVERWRITE)
        ; -----------------------------------------------
        Switch $sResult
            Case 0
                $sResult = "The Sound  file data DOES NOT exist!"
            Case 1
                $sResult = "The Sound  file data WAS backed-up successfully!"
        EndSwitch
        ; -----------------------------------------------
        $sMessage &= $sResult & @CRLF
    Next
    ; -----------------------------------------------
    $sMessage &= @CRLF & "Backup All Sound  File data is now completed..." & @CRLF
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>BackupSoundData
; -----------------------------------------------

In ListBackupFolders1(), when cancelling the listing,, upon selecting "Exit" the entire script is terminated! Is there any way to exit a function and not the entire script?

As always...any assistance in this matter would be greatly appreciated!

Edited by mr-es335
Posted

argumentum,

Tried that...no success!

; -----------------------------------------------
#include <array.au3>
#include <AutoItConstants.au3>
#include <file.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
ListBackupFolders1()
; -----------------------------------------------
Func ListBackupFolders1()
    Local $sBackupFolderPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets"
    ; -----------------
    Local $ArrayFolders = _FileListToArrayRec($sBackupFolderPath, "*", $FLTAR_FOLDERS)
    ; -----------------
    Local $verify = MsgBox(68, "Notice!", "List the backup folders?!")
    ; -----------------------------------------------
    Select
        Case $verify = 6
            _ArrayDisplay($ArrayFolders, "Folder Listing", Default, 64)
        Case $verify = 7
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled. Exiting!", 1)
;~          Exit
            Return
    EndSelect
    ; -----------------------------------------------
    EnterSoundFolderName1()
EndFunc   ;==>ListBackupFolders1
; -----------------------------------------------

 

Posted (edited)

You need some loop to keep it alive, try something similar to:

; -----------------------------------------------
#include <array.au3>
#include <AutoItConstants.au3>
#include <file.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)


ListBackupFolders1()
While 1
    Sleep(10)
WEnd

; -----------------------------------------------
Func ListBackupFolders1()
    Switch MsgBox(68, "Notice!", "List the backup folders?!")
        Case 6
            Local $sBackupFolderPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets"
            Local $ArrayFolders = _FileListToArrayRec($sBackupFolderPath, "*", $FLTAR_FOLDERS)
            _ArrayDisplay($ArrayFolders, "Folder Listing", Default, 64)
        Case 7
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled. Exiting!", 1)
    EndSwitch
EndFunc   ;==>ListBackupFolders1

 

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Posted (edited)
16 hours ago, mr-es335 said:

In ListBackupFolders1(), when cancelling the listing,, upon selecting "Exit" the entire script is terminated! Is there any way to exit a function and not the entire script?

1) I don't understand this "selecting Exit", where is it found in the script ?
If we're talking of the 1st MsgBox found in the ListBackupFolders1(), then it is correctly placed to confirm that the user wants to run this script or not. Your code :

Local $verify = MsgBox(68, "Notice!", "List the backup folders?!")
Select
    Case $verify = 6
        _ArrayDisplay($ArrayFolders, "Folder Listing", Default, 64)
    Case $verify = 7
        MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled. Exiting!", 1)
        Exit
EndSelect

Same as :

Local $verify = MsgBox($MB_ICONINFORMATION + $MB_YESNO, "List the backup folders", "Do you want to run this script ?")
Select
    Case $verify = $IDYES
        _ArrayDisplay($ArrayFolders, "Folder Listing", Default, 64)
    Case $verify = $IDNO
        MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled. Exiting!", 1)
        Exit
EndSelect

If you choose "No", where would you like to "return" in this specific script ?
Choosing "No" is the only way to Exit this script gracefully. If "No" should return to the script, then you'll face this same MsgBox again and again (e.g. each time you choose "No") . Is it what you really want ? I doubt it.

2) Maybe you were talking about something else : could your "cancelling the listing" be related to the listing displayed by _ArrayDisplay ? I doubt that.

3) Now if your question is related to the InputBox found later in the script (which would make more sense) ...

$sSoundsFolderName = InputBox("NOTICE!", "Enter the Sounds Folder Name...", "", "", 150, 130)

...then if you click "Cancel" in the InputBox and don't want to quit the script, that's another question we could discuss.

So in the end, it would be great if you indicate us what is the exact line of your code where you would like to "return to the script" instead of exiting ?

Edit: for the record, in the EnterSoundFolderName1() function, you don't need the While loop :

While $sSoundsFolderName = ""
    $sSoundsFolderName = InputBox("NOTICE!", "Enter the Sounds Folder Name...", "", "", 150, 130)
    ...
WEnd

There's a parameter in InputBox that forces the user to enter something in the InputBox . From the help file :

The second and subsequent characters of the password field can be used to restrict input. Use a space to fill the first character to still see the characters typed. Putting an M after the first character indicates that input is Mandatory; i.e. you must enter something. Nothing will happen if you press the Ok button when there is nothing in the InputBox() . It will not close and return the string.

So this single line should do it, without a While loop :

$sSoundsFolderName = InputBox("NOTICE!", "Enter the Sounds Folder Name...", "", " M", 150, 130)

Because actually (with your initial code) , leaving the InputBox blank and pressing OK continues the script, even with the presence of a While loop : it's not what's expected.

Edited by pixelsearch

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

pixelsearch,

; -----------------------------------------------
ListBackupFolders1()
; -----------------------------------------------
Func ListBackupFolders1()
    Local $sBackupFolderPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets"
    ; -----------------
    Local $ArrayFolders = _FileListToArrayRec($sBackupFolderPath, "*", $FLTAR_FOLDERS)
    ; -----------------
    Local $verify = MsgBox(68, "Notice!", "List the backup folders?!")
    ; -----------------------------------------------
    Select
        Case $verify = 6
            _ArrayDisplay($ArrayFolders, "Folder Listing", Default, 64)
        Case $verify = 7
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled. Exiting!", 1)
            Exit ; Line 16
    EndSelect
    ; -----------------------------------------------
    EnterSoundFolderName()
EndFunc   ;==>ListBackupFolders1
; -----------------------------------------------

Line 16...

Posted
17 hours ago, mr-es335 said:

Is there any way to exit a function and not the entire script?

Line 16, ok. If you really want to do this, then you can add a While... WEnd loop in your function :

Func ListBackupFolders1()
    While True
        ...
    Wend
EndFunc

Then add ExitLoop inside the While...Wend loop, at the place where you want to terminate the loop . It will terminate your function (if no code is found after the WEnd statement) . Scripting it like this allows also to use ContinueLoop in case you want to loop again, without leaving the function (we talked about this in another of your thread iirc)

 

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

Good day,

Maybe...just maybe, I should have included more of the script? Here is a condensed sampling:

; -----------------------------------------------
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Main()
; -----------------------------------------------
Func Main()
    GUICreate("Test Menu", 150, 20, 1410, 22)
    ; -----------------------------------------------
    Global $mBackup = GUICtrlCreateMenu("Backup Menu")
    Global $mBackupSrcData = GUICtrlCreateMenuItem("Backup", $mBackup)
    ; -----------------
    Global $mExitMenu = GUICtrlCreateMenu("Exit Menu")
    Global $mExitMe = GUICtrlCreateMenuItem("Exit", $mExitMenu)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
                ; -----------------
                ; Backup Menu
            Case $mBackupSrcData
                ListBackupFolders()
                ; -----------------
                ; Exit Menu
            Case $mExitMe
                ExitMe()
        EndSwitch
    WEnd
EndFunc   ;==>Main
; -----------------------------------------------
; -----------------------------------------------
; Backup Menu Functions
Func ListBackupFolders()
    Local $sBackupFolderPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets"
    ; -----------------
    Local $ArrayFolders = _FileListToArrayRec($sBackupFolderPath, "*", $FLTAR_FOLDERS)
    ; -----------------
    Local $verify = MsgBox(68, "Notice!", "List the backup folders?!")
    ; -----------------------------------------------
    Select
        Case $verify = 6
            _ArrayDisplay($ArrayFolders, "Folder Listing", Default, 64)
        Case $verify = 7
            MsgBox($MB_ICONINFORMATION, "Notice!", "The operation was cancelled. Exiting!", 1)
            Exit ; Line 52
    EndSelect
    ; -----------------------------------------------
    EnterSoundFolderName()
EndFunc   ;==>ListBackupFolders
; -----------------------------------------------
Func EnterSoundFolderName()
    Local $sRootPath = "E:\Text\Native Instruments\Guitar Rig 5\Presets\"
    Local $sSoundsFolderName = ""
    ; -----------------------------------------------
    While $sSoundsFolderName = ""
        $sSoundsFolderName = InputBox("NOTICE!", "Enter the Sounds Folder Name...", "", "", 150, 130)
        ; -----------------
        If @error Then
            MsgBox($MB_ICONWARNING, "Notice!", "The operation was cancelled. Exiting!")
;~          Exit
        Else
            Local $sBackupPath = DirCreate($sRootPath & $sSoundsFolderName)
            $sBackupPath = $sRootPath & $sSoundsFolderName
            DoesBackupFolderExist($sBackupPath)
        EndIf
    WEnd
EndFunc   ;==>EnterSoundFolderName
; -----------------------------------------------
Func DoesBackupFolderExist($sBackupPath)
    Local $sDoesFolderExist = FileExists($sBackupPath)
    ; -----------------------------------------------
    If $sDoesFolderExist Then
        BackupSoundData($sBackupPath)
    Else
        CreateBackupFolder($sBackupPath)
    EndIf
EndFunc   ;==>DoesBackupFolderExist
; -----------------------------------------------
Func CreateBackupFolder($sBackupPath)
    Local $iStart = 2, $iEnd = 1
    Local $sSrcPath[$iStart] = [$iEnd]
    $sSrcPath[1] = $sBackupPath
    ; -----------------
    Local $sMessage = "Create Backup Folder..." & @CRLF & @CRLF, $iWidth = 450, $iHeight = 135
    Local $iOpt = 5, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    ; -----------------------------------------------
    For $i = 1 To $sSrcPath[0]
        Local $sResult = DirCreate($sSrcPath[$i])
        $sBackupPath = $sSrcPath[$i]
        ; -----------------------------------------------
        Switch $sResult
            Case 0
                $sResult = "The Backup Folder DOES NOT exist!"
            Case 1
                $sResult = "The Backup Folder WAS created successfully!"
        EndSwitch
        ; -----------------------------------------------
        $sMessage &= $sResult & @CRLF
    Next
    ; -----------------------------------------------
    $sMessage &= @CRLF & "Creating Backup Folder is now completed..." & @CRLF
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
    ; -----------------------------------------------
    BackupSoundData($sBackupPath)
EndFunc   ;==>CreateBackupFolder
; -----------------------------------------------
Func BackupSoundData($sBackupPath)
    Local $iStart = 2, $iEnd = 1
    Local $sSrcPath[$iStart] = [$iEnd]
    $sSrcPath[1] = "E:\Text\Native Instruments\Guitar Rig 5\Sounds\*.ngrr"
    ; -----------------
    Local $sDstPath[$iStart] = [$iEnd]
    $sDstPath[1] = $sBackupPath
    ; -----------------
    Local $sMessage = "Backup All Sound File data..." & @CRLF & @CRLF, $iWidth = 450, $iHeight = 135
    Local $iOpt = 5, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    ; -----------------------------------------------
    For $i = 1 To $sSrcPath[0]
        Local $sResult = FileCopy($sSrcPath[$i], $sDstPath[$i], $FC_OVERWRITE)
        ; -----------------------------------------------
        Switch $sResult
            Case 0
                $sResult = "The Sound  file data DOES NOT exist!"
            Case 1
                $sResult = "The Sound  file data WAS backed-up successfully!"
        EndSwitch
        ; -----------------------------------------------
        $sMessage &= $sResult & @CRLF
    Next
    ; -----------------------------------------------
    $sMessage &= @CRLF & "Backup All Sound  File data is now completed..." & @CRLF
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>BackupSoundData
; -----------------------------------------------
; -----------------------------------------------
; Exit Menu Functions
Func ExitMe()
    Exit
EndFunc   ;==>ExitMe
; -----------------------------------------------

The line in question is Line 52.

Posted (edited)
1 hour ago, mr-es335 said:

Maybe...just maybe, I should have included more of the script?

Yes, you definitely should have started with this last script, which makes much more sense.
So now what's wrong with @argumentum suggestion in his post ?

18 hours ago, argumentum said:

Replace the Exit with a Return.

Line 52 : just change Exit with Return and you're back to your menu . argumentum suggestion couldn't make it with your 1st "truncated" script but now it should be ok... or I'm still missing something :D

Edited by pixelsearch
typo

"I think you are searching a bug where there is no bug... don't listen to bad advice."

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