Jump to content

Restarting a While Loop based on Buttons Pressed in the MSGBOX


Recommended Posts

Hello Autoit Users,

 

Inside a while a loop, I have a drop down list and when an entry is selected, a msgbox appears asking the user to confirm or cancel the selection. When OK is pressed, the code continues to the next part. 

Up until now, I had coded it in such a way that when cancel is pressed, the code exits. and the user has to restart the application in order to access the drop down list again.

Is it in any way possible that, when cancel is pressed, the code jumps back to start of the while loop (or in better layman terms, to the parent GUI)

:)

any help here would be appeiciated. This is just a ""nice to have Feature. Seems simple enough. but i am not able to gather my thoughts for this. 

 

 

Regards,

NaveeN

Link to comment
Share on other sites

  • Moderators

The short answer is "Yes, of course it is possible".

If you would like more specific assistance, please post your code so we aren't guessing at what you're trying to do.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi Jlogan3o13.

 

:).. you are right !!! Here the part of my code,... 

What happens here is, if i press retry, the code exits !! which i am not able to understand why

 

Global $Point_2_Restart

While 1
          Switch GUIGetMsg()
              Case $GUI_EVENT_CLOSE
                  Exit
               Case $hCombo
                  For $i = 1 To $var[0][0]
                     Switch GUICtrlRead($hCombo)
                        Case $var[$i][0]
                           $iButton =  MsgBox(6, "Server Selected",  "Selected Location:"& @CRLF & $var[$i][0] & @CRLF & $var[$i][1])
                           if $iButton = 2 then Exit
                           if $iButton = 10 then $Point_2_Restart ........ Go back to start of the loop
                           
                           Here comes the actual code to be executed if OK is pressed.
                    EndSwitch
                  Next
              ExitLoop
          EndSwitch
      WEnd       

Link to comment
Share on other sites

Here is another way you could also try:

#include <Array.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_hCombo
Global $g_aCombo[3][2] = [["Server1", "\\Server1\Share"], ["Server2", "\\Server2\Share"], ["Server3", "\\Server3\Share"]]

Example()

Func Example()
    Local $hGUI = GUICreate("(UDF) ComboBox Create", 400, 296)
    $g_hCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUICtrlSetData($g_hCombo, _ArrayToString($g_aCombo, "|", -1, -1, "|", 0, 0))
    GUISetState()
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $iMsgBox
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word
    Switch $iIDFrom
        Case $g_hCombo
            Switch $iCode
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    $iMsgBox = MsgBox(6,'Server Selected', "Selected Location: " & GUICtrlRead($g_hCombo) & @CRLF & "Share Name: " & $g_aCombo[_GUICtrlComboBox_GetCurSel($g_hCombo)][1])
                    If $iMsgBox = 11 Then
                        ;~ Continue was selected
                        ;~ Code to be executed goes here
                    EndIf
                    ;~ Either Cancel or Try Again was selected
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

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