Jump to content
Sign in to follow this  
ComicsMan

Help in Crating a Simple Timer (Code Inside)

Recommended Posts

ComicsMan

Hi,

First of all i am new here its my first post :) (be gentle)

I wanted to create a simple timer with a start and stop button

I created a while loop which sleeps and then runs a msgbox.

The loop was suppose to stop when i press the stop button

Which was suppose to udate the $i int to 1 and stop the loop.

It seems that when the while loop runs the other buttons are not working...

#include <GUIConstants.au3>
$i = 0
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 258, 138, 193, 155)
$Input1 = GUICtrlCreateInput("3000", 24, 40, 129, 21)
$Label1 = GUICtrlCreateLabel("Enter Time", 56, 16, 55, 17)
$Label2 = GUICtrlCreateLabel("Message", 56, 78, 47, 17)
$Input2 = GUICtrlCreateInput("", 22, 98, 129, 21)
$Button1 = GUICtrlCreateButton("Start", 176, 40, 65, 25, 0)
$Button2 = GUICtrlCreateButton("Stop", 176, 93, 65, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
 Case $Button1
  $Timer_Time=GUICtrlRead(3)
  $Timer_Text=GUICtrlRead(6)         
  While $i <1
   Sleep ($Timer_Time)
   MsgBox(0, "Finished Sleeping",$Timer_Time & @LF & $Timer_Text & @LF & $i)
 WEnd
 Case $Button2
  $i = 1
Case $GUI_EVENT_CLOSE
 Exit
EndSwitch
WEnd

Any help would be appreciated

P.S

How do i create a code based on the action taken in msgbox (yes, no, etc)

Thanks

ComicsMan

Share this post


Link to post
Share on other sites
ComicsMan

Look here

After reviewing your code i tried it my self, but its not really working the way your code did :)

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 258, 138)
$Input1 = GUICtrlCreateInput("3000", 24, 40, 129, 21)
$Label1 = GUICtrlCreateLabel("Enter Time", 56, 16, 55, 17)
$Label2 = GUICtrlCreateLabel("Message", 56, 78, 47, 17)
$Input = GUICtrlCreateInput("", 22, 98, 129, 21)
$Start = GUICtrlCreateButton("Start", 176, 40, 65, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 176, 93, 65, 25, 0)
GUISetState(@SW_SHOW)

$run = 0

While 1
 $Msg = GUIGetMsg()
 
 If $msg = $GUI_EVENT_CLOSE Then ExitLoop
 If $msg = $Start Then $run = 1
 If $msg = $Stop Then $run = 0
 If $run Then
  $Timer_Time=GUICtrlRead(3)
  $Timer_Text=GUICtrlRead(6)
  Sleep($Timer_Time)
  MsgBox(0, "Finished Sleeping",$Timer_Time & @LF & $Timer_Text & @LF & $run)
 EndIf
WEnd

Can you help?

ComicsMan

Share this post


Link to post
Share on other sites
Valuater

Maybe

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 258, 138)
$Input1 = GUICtrlCreateInput("3000", 24, 40, 129, 21)
$Label1 = GUICtrlCreateLabel("Enter Time", 56, 16, 55, 17)
$Label2 = GUICtrlCreateLabel("Message", 56, 78, 47, 17)
$Input = GUICtrlCreateInput("", 22, 98, 129, 21)
$Start = GUICtrlCreateButton("Start", 176, 40, 65, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 176, 93, 65, 25, 0)
GUISetState(@SW_SHOW)

Local $run = 0, $Timer_Text = "", $Timer_Time = 0, $clock = TimerInit()

While 1
    $Msg = GUIGetMsg()

    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $Msg = $Start Then
        $run = 1
        $clock = TimerInit()
        $Timer_Time = GUICtrlRead(3)
        $Timer_Text = GUICtrlRead(6)
    EndIf
    If $Msg = $Stop Then $run = 0
    If $run Then
        $Diff = TimerDiff($clock)
        If $Diff >= $Timer_Time Then
            MsgBox(0, "Finished Sleeping", $Timer_Time & @LF & $Timer_Text & @LF & $run)
            $clock = TimerInit()
        EndIf
    EndIf
WEnd

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
ComicsMan

Maybe

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 258, 138)
$Input1 = GUICtrlCreateInput("3000", 24, 40, 129, 21)
$Label1 = GUICtrlCreateLabel("Enter Time", 56, 16, 55, 17)
$Label2 = GUICtrlCreateLabel("Message", 56, 78, 47, 17)
$Input = GUICtrlCreateInput("", 22, 98, 129, 21)
$Start = GUICtrlCreateButton("Start", 176, 40, 65, 25, 0)
$Stop = GUICtrlCreateButton("Stop", 176, 93, 65, 25, 0)
GUISetState(@SW_SHOW)

Local $run = 0, $Timer_Text = "", $Timer_Time = 0, $clock = TimerInit()

While 1
    $Msg = GUIGetMsg()

    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $Msg = $Start Then
        $run = 1
        $clock = TimerInit()
        $Timer_Time = GUICtrlRead(3)
        $Timer_Text = GUICtrlRead(6)
    EndIf
    If $Msg = $Stop Then $run = 0
    If $run Then
        $Diff = TimerDiff($clock)
        If $Diff >= $Timer_Time Then
            MsgBox(0, "Finished Sleeping", $Timer_Time & @LF & $Timer_Text & @LF & $run)
            $clock = TimerInit()
        EndIf
    EndIf
WEnd

8)

Thanks XSkin :D

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.