Sign in to follow this  
Followers 0
supersonic

countdown for while/wend

6 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#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

Share this post


Link to post
Share on other sites

Perfect! Thank you! :D

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Maybe the 2nd while/wend loop is responsible for this?

Edit:

When I disabled the line

AutoItSetOption("GUIOnEventMode", 1)

... both loops work fine - but the GUI of function "ndm()" can't be closed.

Edited by supersonic

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0