Jump to content

countdown for while/wend


Recommended Posts

Hi,

I'm trying to make an countdown sequence for the following while/wend loop:

Local $ndmCounter = 5
    While $ndmCounter > 0
        GUICtrlSetData($ndmButton, "OK (" & $ndmCounter & ")")
        $ndmCounter = $ndmCounter - 1
        Sleep(1000)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($ndmGUI)
                ExitLoop
            Case $ndmButton
                _GUICtrlComboBox_GetLBText($ndmComboBox, _GUICtrlComboBox_GetCurSel($ndmComboBox), $ndmDummy)
                RegWrite("HKCU\Software\" & $programName, "ndm", "REG_SZ", $ndmDummy)
                GUIDelete($ndmGUI)
                ExitLoop
        EndSwitch
    WEnd

Problems:

1. I can't leave the loop by pressing OK button or closing GUI.

2. A selection (ComboBox) will be only recognized when it was chosen via keyboard. Input via mouse will be ignored.

Any ideas?

Link to comment
Share on other sites

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 329, 211, 417, 266)

$Button1 = GUICtrlCreateButton("Button1", 16, 8, 129, 33, 0)
GUICtrlSetOnEvent(-1, "exit_now")
$Combo1 = GUICtrlCreateCombo("Combo1", 40, 88, 129, 25)
GUICtrlSetData(-1, "a|b|c|d|e|g|h")

GUISetOnEvent($GUI_EVENT_CLOSE, "exit_now")
GUISetState(@SW_SHOW)



Local $ndmCounter = 10
While $ndmCounter > 0
    GUICtrlSetData($Button1, "OK (" & $ndmCounter & ")")
    $ndmCounter = $ndmCounter - 1
    Sleep(1000)
WEnd

Func exit_now()

MsgBox(0,"Combo was",guictrlread($Combo1),0)
GUIDelete($Form1)
EndFunc  ;==>exit_now

Hope this helps

Edited by Aceguy
Link to comment
Share on other sites

Hi,

the loop works pretty well now, but when leaving the while/wend loop of function "ndm()" the script hangs.

Here's a part of what I have coded so far:

Func ndm($ndmTarget)
    AutoItSetOption("GUIOnEventMode", 1) ; Opt
    Local $ndmCounter = 10
    $ndmArray = xmlQueryGCN($ndmTarget)
    If $ndmArray = 2 Then
        Return 2
    Else
        $ndmGUI = GUICreate($programName & " - Network Drive Mapping(s)" & Chr(133), 400, 50, -1, -1) ; Asc("")
        $ndmButton = GUICtrlCreateButton("OK", 1, 24, 398, 25)
        GUICtrlSetOnEvent(-1, "exit_now")
        $ndmComboBox = GUICtrlCreateCombo("", 1, 1, 398, 21)
        $ndmDummy = RegRead("HKCU\Software\" & $programName, "ndm")
        If @error Then
            $ndmDummy = ""
        EndIf
        For $i = 1 to $ndmArray[0]
            If Not StringInStr($ndmArray[$i], "Global", 0) Then
                If $i <> $ndmArray[0] Then
                    GUICtrlSetData(-1, $ndmArray[$i] & "|", $ndmDummy)
                Else
                    GUICtrlSetData(-1, $ndmArray[$i], $ndmDummy)
                EndIf
            EndIf
        Next
        GUISetOnEvent($GUI_EVENT_CLOSE, "exit_now")
        GUISetState(@SW_SHOW)
    EndIf
    ; <...>
    While $ndmCounter > 0
        GUICtrlSetData($ndmButton, "OK (" & $ndmCounter & ")")
        $ndmCounter = $ndmCounter - 1
        Sleep(1000)
    WEnd
EndFunc


Func exit_now()
    MsgBox(0, "", GUICtrlRead($ndmComboBox))
    GUIDelete($ndmGUI)
EndFunc


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        GUIDelete($lvGUI)
        ExitLoop
    EndIf
WEnd

Can somebody help?

Link to comment
Share on other sites

you only need to put AutoItSetOption("GUIOnEventMode", 1) ONCE at the top of the script.

and not in a function.

is this you full code.??

GUISetOnEvent($GUI_EVENT_CLOSE, "exit_now")

GUISetState(@SW_SHOW)

also only need to be once at top of script.

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