Jump to content

Help in Crating a Simple Timer (Code Inside)


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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