Jump to content

(OnEventMode) How to pause function when child GUI is opened


Recommended Posts

I am using OnEventMode for my program. The script will search for the computer name in active directory and return some computer names when a number is entered into the input field. e.g. enter "10000" (the computer names returned from AD are computer10000a, computer10000b, computer10000c)

When the list of computer names is returned from AD, the program opens a child GUI displays the list, the user will have option to select which the computer they want to proceed, then click OK to continue the rest of the _init() function. Exactly like how _ArrayDisplay() would work (it pauses the function until popup window is closed). Because _ArrayDisplay() is not customizable to the way I need it to be, so I will create my own custom child GUI.
The problem I am having is that I can't find a way to pause the init() function until the child window is closed, currently the Init() function continutes to run when the child window is opened.
I am hoping I could get some help or guidance here. 
Thanks in advance :)

Opt("GUIOnEventMode", 1)

_mainGUI()

Global $finalComputerName
Global $getComputerName = "10000" ;correct hostname is "computer10000a"

Func _mainGUI()
    $ConnectButton = GUICtrlCreateButton("Connect", 324, 437, 100, 25, -1, -1)
    GUICtrlSetOnEvent(-1, "_connectBtn")
    
    
    While 1
        If $connectButtonFlg = True Then
            _connectButtonAction()
            $connectButtonFlg = False
        Else
            Sleep(100)
        EndIf
    WEnd
EndFunc

Func _selectComputerNameGUI($computerName)
     $SelectComputerName = GUICreate("child GUI", 200, 200, 350, 350)
     GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
     ConsoleWrite($computerName[1])
     GUISetState()
EndFunc   ;==>_selectComputerNameGUI


Func _connectBtn()
    Switch @GUI_CtrlId
        Case $ConnectButton
            $connectButtonFlg = True
    EndSwitch
EndFunc   ;==>_connectButton

Func _connectButtonAction()
    If _init(1) == 1 Then
        ;do other stuff below
    EndIf
EndFunc

Func _init()
    If StringRegExp($getComputerName, '[^0-9]') Or Number($getComputerName) < 10000 Then
        _GUICtrlEdit_AppendText($StatusOutput, "connecting to " & $getComputerName & @CRLF)
    Else
        $existingContentStatusOutput = _GUICtrlEdit_GetTextLen($StatusOutput)
        _GUICtrlEdit_AppendText($StatusOutput, "Detected numeric input, searching for computer name..." & @CRLF)
        $searchComputerNamePID = Run(@ComSpec & " /c dsquery computer -name *" & $getComputerName & "* -d domainName -o rdn", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
        While 1
                $searchedComputerName &= StdoutRead($searchComputerNamePID)
                If @error Then ExitLoop
        WEnd
        $searchedComputerName = StringReplace($searchedComputerName, '"', "")
        $searchedComputerName = StringStripWS($searchedComputerName, 3)
        $searchedComputerName = StringRegExpReplace($searchedComputerName, @CRLF, ",")
        $searchedComputerName = StringSplit($searchedComputerName, ",")

        If ($searchedComputerName[1] == "") Then
            _MsgBoxEx(64 + 262144, $programTitle, "Host not found.")
        Else
            _selectComputerNameGUI($searchedComputerName)
            ;I want to have the script pause until user has selected a value from _selectComputerNameGUI(), or when child window is closed
        EndIf
    EndIf
    
    If _IsValidIP($getComputerName) Then
        $finalComputerName = _TCPIpToName($getComputerName)
        If @error Then
            _MsgBoxEx(64 + 262144, $programTitle, "Host not found.")
        Else
            Local $IPAddress = $getComputerName
        EndIf
    Else
        Local $IPAddress = TCPNameToIP($getComputerName)
        If @error Then
            _MsgBoxEx(64 + 262144, $programTitle, "Host not found.")
        Else
            $finalComputerName = $getComputerName
        EndIf
    EndIf
        
    _GUICtrlEdit_AppendText($StatusOutput, "Computer: " & $finalComputerName & @CRLF)
    _GUICtrlEdit_AppendText($StatusOutput, "IP: " & $IPAddress & @CRLF)
    Return 1
EndFunc

 

Edited by wuruoyu
Link to comment
Share on other sites

Your script has other problems:

+>11:20:20 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Temp\asdf.au3
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(14,30) : warning: $connectButtonFlg: possibly used before declaration.
        If $connectButtonFlg =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(25,36) : warning: $GUI_EVENT_CLOSE: possibly used before declaration.
     GUISetOnEvent($GUI_EVENT_CLOSE,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(33,28) : warning: $ConnectButton: possibly used before declaration.
        Case $ConnectButton
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(44,13) : error: _init() called by a previous line with 1 arg(s). Max = 0. First previous line calling this Func is 39.
Func _init()
~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(46,46) : warning: $StatusOutput: possibly used before declaration.
        _GUICtrlEdit_AppendText($StatusOutput,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(50,162) : warning: $STDOUT_CHILD: possibly used before declaration.
        $searchComputerNamePID = Run(@ComSpec & " /c dsquery computer -name *" & $getComputerName & "* -d domainName -o rdn", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(52,76) : warning: $searchedComputerName possibly not declared/created yet
                $searchedComputerName &= StdoutRead($searchComputerNamePID)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(61,49) : warning: $programTitle: possibly used before declaration.
            _MsgBoxEx(64 + 262144, $programTitle,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(25,36) : error: $GUI_EVENT_CLOSE: undeclared global variable.
     GUISetOnEvent($GUI_EVENT_CLOSE,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(33,28) : error: $ConnectButton: undeclared global variable.
        Case $ConnectButton
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(46,46) : error: $StatusOutput: undeclared global variable.
        _GUICtrlEdit_AppendText($StatusOutput,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(50,162) : error: $STDOUT_CHILD: undeclared global variable.
        $searchComputerNamePID = Run(@ComSpec & " /c dsquery computer -name *" & $getComputerName & "* -d domainName -o rdn", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(61,49) : error: $programTitle: undeclared global variable.
            _MsgBoxEx(64 + 262144, $programTitle,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(25,45) : error: _exit(): undefined function.
     GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(46,91) : error: _GUICtrlEdit_AppendText(): undefined function.
        _GUICtrlEdit_AppendText($StatusOutput, "connecting to " & $getComputerName & @CRLF)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(48,77) : error: _GUICtrlEdit_GetTextLen(): undefined function.
        $existingContentStatusOutput = _GUICtrlEdit_GetTextLen($StatusOutput)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(61,68) : error: _MsgBoxEx(): undefined function.
            _MsgBoxEx(64 + 262144, $programTitle, "Host not found.")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(68,35) : error: _IsValidIP(): undefined function.
    If _IsValidIP($getComputerName)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(69,59) : error: _TCPIpToName(): undefined function.
        $finalComputerName = _TCPIpToName($getComputerName)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Temp\asdf.au3 - 12 error(s), 7 warning(s)
!>11:20:23 AU3Check ended. Press F4 to jump to next error.rc:2
+>11:20:23 AutoIt3Wrapper Finished.
>Exit code: 2    Time: 6.124

 

Link to comment
Share on other sites

Forgetting the errors (assuming you didn't post the whole script) :

        Else
            _selectComputerNameGUI($searchedComputerName)
            ;I want to have the script pause until user has selected a value from _selectComputerNameGUI(), or when child window is closed
        EndIf

For this you must make the _selectComputerNameGUI() func blocking , that means you need a loop inside the func and the ability to exit this loop on child gui event

Link to comment
Share on other sites

4 hours ago, AutoBert said:

Your script has other problems:

+>11:20:20 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Temp\asdf.au3
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(14,30) : warning: $connectButtonFlg: possibly used before declaration.
        If $connectButtonFlg =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(25,36) : warning: $GUI_EVENT_CLOSE: possibly used before declaration.
     GUISetOnEvent($GUI_EVENT_CLOSE,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(33,28) : warning: $ConnectButton: possibly used before declaration.
        Case $ConnectButton
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(44,13) : error: _init() called by a previous line with 1 arg(s). Max = 0. First previous line calling this Func is 39.
Func _init()
~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(46,46) : warning: $StatusOutput: possibly used before declaration.
        _GUICtrlEdit_AppendText($StatusOutput,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(50,162) : warning: $STDOUT_CHILD: possibly used before declaration.
        $searchComputerNamePID = Run(@ComSpec & " /c dsquery computer -name *" & $getComputerName & "* -d domainName -o rdn", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(52,76) : warning: $searchedComputerName possibly not declared/created yet
                $searchedComputerName &= StdoutRead($searchComputerNamePID)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(61,49) : warning: $programTitle: possibly used before declaration.
            _MsgBoxEx(64 + 262144, $programTitle,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(25,36) : error: $GUI_EVENT_CLOSE: undeclared global variable.
     GUISetOnEvent($GUI_EVENT_CLOSE,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(33,28) : error: $ConnectButton: undeclared global variable.
        Case $ConnectButton
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(46,46) : error: $StatusOutput: undeclared global variable.
        _GUICtrlEdit_AppendText($StatusOutput,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(50,162) : error: $STDOUT_CHILD: undeclared global variable.
        $searchComputerNamePID = Run(@ComSpec & " /c dsquery computer -name *" & $getComputerName & "* -d domainName -o rdn", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(61,49) : error: $programTitle: undeclared global variable.
            _MsgBoxEx(64 + 262144, $programTitle,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(25,45) : error: _exit(): undefined function.
     GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(46,91) : error: _GUICtrlEdit_AppendText(): undefined function.
        _GUICtrlEdit_AppendText($StatusOutput, "connecting to " & $getComputerName & @CRLF)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(48,77) : error: _GUICtrlEdit_GetTextLen(): undefined function.
        $existingContentStatusOutput = _GUICtrlEdit_GetTextLen($StatusOutput)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(61,68) : error: _MsgBoxEx(): undefined function.
            _MsgBoxEx(64 + 262144, $programTitle, "Host not found.")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(68,35) : error: _IsValidIP(): undefined function.
    If _IsValidIP($getComputerName)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\asdf.au3"(69,59) : error: _TCPIpToName(): undefined function.
        $finalComputerName = _TCPIpToName($getComputerName)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Temp\asdf.au3 - 12 error(s), 7 warning(s)
!>11:20:23 AU3Check ended. Press F4 to jump to next error.rc:2
+>11:20:23 AutoIt3Wrapper Finished.
>Exit code: 2    Time: 6.124

Thanks for the quick reply. Sorry this is not the complete script.

 

Link to comment
Share on other sites

3 hours ago, mikell said:

Forgetting the errors (assuming you didn't post the whole script) :

        Else
            _selectComputerNameGUI($searchedComputerName)
            ;I want to have the script pause until user has selected a value from _selectComputerNameGUI(), or when child window is closed
        EndIf

For this you must make the _selectComputerNameGUI() func blocking , that means you need a loop inside the func and the ability to exit this loop on child gui event

Func _selectComputerNameGUI($phsaComputerName)
     $SelectComputerName = GUICreate("Gui 2", 200, 200, 350, 350)
     GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
     $hButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30)
     ;GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function
     ConsoleWrite($phsaComputerName[1])
     GUISetState()
     While 1
        If $userSelectedAComputerFlg = True Then
            $userSelectedAComputerFlg = False
            GUIDelete($SelectComputerName)
            ExitLoop
        Else
            Sleep(100)
        EndIf
    WEnd
 EndFunc   ;==>_selectComputerNameGUI
 
 Func _exit()
    Switch @GUI_WINHANDLE
        Case $Main
            Exit
        Case $SelectComputerName
            $userSelectedAComputerFlg = True
    EndSwitch
EndFunc   ;==>_exit

Thank you for pointing me to the right direction. As you've suggested, a loop inside the child GUI seem to have paused the _init() function. :)

Edited by wuruoyu
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...