Jump to content
Sign in to follow this  
nonorai

GUI with loop

Recommended Posts

nonorai

Hi helper,

I've created a program that send key 9 to a window after some secs (which user select). Everything is create but only for the 1st time (the loop does not work). Can anyone help me to look into the problem :) many thanks for help

#include <Date.au3>
#include <GUIConstantsEx.au3>
Global $Start, $Stop, $Exit, $msg, $Time, $TimeOP, $Flag
Global $Timer, $Secs, $Mins, $Hour, $Timer1

GUICreate("Custom Msgbox", 210, 80)

GUICtrlCreateLabel("Thoi gian hoi (s)", 10, 10)
$Time = GUICtrlCreateInput ("s", 90, 7, 30, 20)
$Start = GUICtrlCreateButton("Start", 10, 50, 50, 20)
$Stop = GUICtrlCreateButton("Stop", 80, 50, 50, 20)
$Exit = GUICtrlCreateButton("Exit", 150, 50, 50, 20)
GUISetState() ; display the GUI
$Timer = TimerInit()
AdlibRegister("Timer", 50)

While 1
   $msg = GUIGetMsg()
   Select
 Case $msg = $Start
$TimeOP = GUICtrlRead($Time)
Action ()
 Case $msg = $Exit
MsgBox(0, "Thoat", "Bye")
Exit
 Case $msg = $GUI_EVENT_CLOSE
MsgBox(0, "You clicked on", "Close")
Exit
   EndSelect
WEnd

Func Timer()
  _TicksToTime(Int(TimerDiff($Timer)), $Hour, $Mins, $Secs)
   If $Mins < 0 Then
 $Timer1 = $Mins
   Else 
 $Timer1 = $Mins * 60 + $Secs
   EndIf
EndFunc   ;==>Timer

Func Action()
   GUICtrlSetState($Time, $GUI_DISABLE)
   While 1
 If $Timer1 = $TimeOP Then
ToolTip($Timer1, 0, 0)
Send("9")
$Timer1 = 0
 EndIf
 If $msg = $Stop Then
GUICtrlSetState($Time, $GUI_ENABLE)
ExitLoop
 EndIf
   WEnd
EndFunc
Edited by nonorai

Share this post


Link to post
Share on other sites
FireFox

Hi,

Welcome to the autoit forum :)

 

AutoIt is a single threaded language, you can not run two (or more) While at the same moment.

Hence in your sub While the $msg var won't be updated (same thing for the $Timer1 var).

 

The trick is to put everything in the main loop with a condition :

#include <Date.au3>
#include <GUIConstantsEx.au3>
 
Global $_fAction = False
 
Local $iBtnStart = 0, $iBtnStop = 0, $iBtnExit = 0, $iMsg = 0, $sTimeOP = ""
Global $hTimer = 0, $_iTimer1 = 0, $_iInputTime = 0
 
GUICreate("Custom Msgbox", 210, 80)
 
GUICtrlCreateLabel("Thoi gian hoi (s)", 10, 10)
$_iInputTime = GUICtrlCreateInput("s", 90, 7, 30, 20)
$iBtnStart = GUICtrlCreateButton("Start", 10, 50, 50, 20)
$iBtnStop = GUICtrlCreateButton("Stop", 80, 50, 50, 20)
$iBtnExit = GUICtrlCreateButton("Exit", 150, 50, 50, 20)
GUISetState() ; display the GUI
 
$hTimer = TimerInit()
AdlibRegister("Timer", 50)
 
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $iBtnStart
            $sTimeOP = GUICtrlRead($_iInputTime)
            Action()
        Case $iBtnExit
            MsgBox(0, "Thoat", "Bye")
            ExitLoop ;also exits the script
        Case $GUI_EVENT_CLOSE
            MsgBox(0, "You clicked on", "Close")
            ExitLoop
    EndSwitch
 
    If $_fAction Then
        If $_iTimer1 = Number($sTimeOP) Then
            ToolTip($_iTimer1, 0, 0)
            Send("9")
            $_iTimer1 = 0
        EndIf
        If $iMsg = $iBtnStop Then
            GUICtrlSetState($_iInputTime, $GUI_ENABLE)
            ExitLoop
        EndIf
    EndIf
WEnd
 
GUIDelete()
 
Func Timer()
    Local $iHour = 0, $iMin = 0, $iSec = 0
    _TicksToTime(Int(TimerDiff($hTimer)), $iHour, $iMin, $iSec)
    If $iMin < 0 Then
        $_iTimer1 = $iMin
    Else
        $_iTimer1 = $iMin * 60 + $iSec
    EndIf
EndFunc   ;==>Timer
 
Func Action()
    GUICtrlSetState($_iInputTime, $GUI_DISABLE)
    $_fAction = True
EndFunc   ;==>Action
Br, FireFox. Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  

×