Jump to content

Return ExitLoop From Func to Exit Parent Func?


rm4453
 Share

Recommended Posts

Hello

 

I want to return exitloop to cause my script to stop parsing data if the user cancels an inputbox *I have lots of these inputboxes so I want to just do an over all easy non repetitive @error check for all of the inputboxes where if the user cancels any inputbox it stops parsing pops up a messagebox that says "Template Generation Cancelled!" & continue running normally as if user hadn't pressed anything.

 

*EDIT IS HERE:

Is it as simple as returning ExitLoop 2 while wrapping the parsing in a While loop that increments $i at the end to cause it to exit after 1 parse?

ex:

Func CPU()

While $i < 1

;parse here etc...
Input("Server Location?", "Please Define The Server Location:", "")

$i += 1

Wend

EndFunc

Func Input($1, $2, $3)

$input = Inputbox($1, $2, $3)
If @error = 1 Then Return ExitLoop 2

EndFunc

*END OF EDIT

 

I have the following code:

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Description=CNOC Template Generator
#AutoIt3Wrapper_Res_Fileversion=1.0.0.8
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_ProductName=Automatic Template Generator
#AutoIt3Wrapper_Res_ProductVersion=1.0.0.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiStatusBar.au3>
#Region ### START Koda GUI section ### Form=
$Template_Generator = GUICreate("Template_Generator", 615, 480, 192, 124, BitOR($WS_THICKFRAME, $WS_VISIBLE))

$output = GUICtrlCreateEdit("", 24, 24, 569, 321, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$generate = GUICtrlCreateButton("Generate Template", 105, 368, 113, 49)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$copyTitle = GUICtrlCreateButton("Copy Title", 235, 368, 69, 22)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$copyCI = GUICtrlCreateButton("Copy CI", 309, 368, 69, 22)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$copyPID = GUICtrlCreateButton("Copy Event ID *NetCool*", 235, 395, 143, 22)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$copyTemplate = GUICtrlCreateButton("Copy Template", 396, 368, 113, 49)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
$status = GUICtrlCreateInput("    Status: Program Loaded Successfully!", 0, 430, 615, 25)
GUICtrlSetState(-1, 128)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$priority = ""
$cID = ""
$loc = ""
$node = ""
$title = ""
$loc = ""
$ip = ""
$vCenter = ""
$tool = ""
$osType = ""
$machineType = ""
$pID = ""
$incTitle = ""

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $copyCI
            If StringInStr($node, "Volume:") Or StringInStr($node, "Virtual:") Or StringInStr($node, "Label:") Then
                ClipPut(StringReplace($node, StringRight($node, 4), ""))
            Else
                ClipPut($node)
            EndIf
            GUICtrlSetData($status, "    Status: The CI Has Been Copied Successfully!")
            ;MsgBox("", "Output Copied!", "The Title Has" & @CRLF & "  Been Copied Successfully!")

        Case $copyTitle
            ClipPut($incTitle)
            GUICtrlSetData($status, "    Status: The Title Has Been Copied Successfully!")
            ;MsgBox("", "Output Copied!", "The Title Has" & @CRLF & "  Been Copied Successfully!")

        Case $copyPID
            ClipPut($pID)
            GUICtrlSetData($status, "    Status: The Event ID Has Been Copied Successfully!")
            ;MsgBox("", "Output Copied!", "The Event ID Has" & @CRLF & "  Been Copied Successfully!")

        Case $copyTemplate
            ClipPut(GUICtrlRead($output))
            GUICtrlSetData($status, "    Status: The Output Has Been Copied Successfully!")
            ;MsgBox("", "Output Copied!", "The Output Has" & @CRLF & "  Been Copied Successfully!")

        Case $generate
            GUICtrlSetData($output, "")
            Local $clip = ClipGet()
            $splitClip = StringSplit($clip, @CRLF)
            ;_ArrayDisplay($splitClip)

            If UBound($splitClip) > 3 Then
                If StringInStr($splitClip[3], "Message:") Then

                    $title = StringStripWS(StringSplit($splitClip[3], "Message:", 1)[2], 3)
                    ;MsgBox("", "", $title)

                    If StringInStr($title, "CPU") Then
                        CPU()
                    ElseIf StringInStr($title, "Volume") Or StringInStr($title, "Virtual") Or StringInStr($title, "Label") Or StringInStr($title, "Datastore") Then
                        STORAGE()
                    ElseIf StringInStr($title, "Memory") Then
                        MEMORY()
                    EndIf

                Else
                    MsgBox("", "No Data?", "Error! No Data Copied!")
                EndIf
            Else
                MsgBox("", "No Data?", "Error! No Data Copied!")
            EndIf

    EndSwitch
WEnd

Func CPU()

;Parse data here also accept user input as below:
Input("Location?", "Please Define Server Location?", "")
;If Not Return ExitLoop continue parsing, otherwise stop parsing.

EndFunc

Func MEMORY()

;Parse data here also accept user input as below:
Input("Location?", "Please Define Server Location?", "")
;If Not Return ExitLoop continue parsing, otherwise stop parsing.

EndFunc

Func STORAGE()

;Parse data here also accept user input as below:
Input("Location?", "Please Define Server Location?", "")
;If Not Return ExitLoop continue parsing, otherwise stop parsing.

EndFunc

Func Input($1, $2, $3)

    If $1 = Default Then $1 = ""
    If $2 = Default Then $2 = ""
    If $3 = Default Then $3 = ""

    If $1 = "" Then $1 = ""
    If $2 = "" Then $2 = ""
    If $3 = "" Then $3 = ""

    $input = InputBox($1, $2, $3)
    
    If @error = 1 Then Return ExitLoop ; I want this 
    If @error = 3 Then MsgBox("", "ERROR!", "ERROR: " & @error & " The InputBox Failed To Open! Please Exit & Re-Open Template Generator!")
    If @error = 4 Then MsgBox("", "FAILED!", "The InputBox Failed To Open! Please Exit & Re-Open Template Generator!")
    If Not @error = 1 Then Return $input

EndFunc   ;==>Input

 

Edited by rm4453
Link to comment
Share on other sites

Maybe something like:

Func CPU()
    Local $sCPU = Input("Location?", "Please Define Server Location?", "")
        If @error Then Return
EndFunc

Func MEMORY()
    Local $sMemory = Input("Location?", "Please Define Server Location?", "")
        If @error Then Return
EndFunc

Func STORAGE()
    Local $sStorage = Input("Location?", "Please Define Server Location?", "")
        If @error Then Return
EndFunc

Func Input($1 = "", $2 = "", $3 = "")
    $input = InputBox($1, $2, $3)
    If @error = 3 Then MsgBox("", "ERROR!", "ERROR: " & @error & " The InputBox Failed To Open! Please Exit & Re-Open Template Generator!")
    If @error = 4 Then MsgBox("", "FAILED!", "The InputBox Failed To Open! Please Exit & Re-Open Template Generator!")
    If Not @error = 1 Then Return SetError(0, 0, $input)
    Return SetError(1, 0, "")
EndFunc   ;==>Input

 

Link to comment
Share on other sites

22 minutes ago, Subz said:

Maybe something like:

Func CPU()
    Local $sCPU = Input("Location?", "Please Define Server Location?", "")
        If @error Then Return
EndFunc

Func MEMORY()
    Local $sMemory = Input("Location?", "Please Define Server Location?", "")
        If @error Then Return
EndFunc

Func STORAGE()
    Local $sStorage = Input("Location?", "Please Define Server Location?", "")
        If @error Then Return
EndFunc

Func Input($1 = "", $2 = "", $3 = "")
    $input = InputBox($1, $2, $3)
    If @error = 3 Then MsgBox("", "ERROR!", "ERROR: " & @error & " The InputBox Failed To Open! Please Exit & Re-Open Template Generator!")
    If @error = 4 Then MsgBox("", "FAILED!", "The InputBox Failed To Open! Please Exit & Re-Open Template Generator!")
    If Not @error = 1 Then Return SetError(0, 0, $input)
    Return SetError(1, 0, "")
EndFunc   ;==>Input

 

Thank You!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...