Sign in to follow this  
Followers 0
nitekram

timer - stopwatch

3 posts in this topic

I have the following so far - I have now wrote this 3 different times - and I know it still is not as good as it could be - I am looking for programming direction.

I am more interested in the Func _Count() area - as I drug the rest of it out of an existing program.

As you can see it is using the while statement to count the seconds - one of my tries was to add tenths of a second or hundreds, but I broke my code and had to start over - this is the start over code.

I would like to make it look like HH:MM:SS and maybe :100's if anyone can suggest a way of doing it.

I am not looking for someone to write it for me - I would like to know how to program it different or better. The Func _Count() part - any suggestions

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Global $start_stop = 0, $stopper = 1
Global $iTimmerStarted = 0, $iAddMin = 0, $iAddHour = 0
Global Const $00zero = "00", $0zero = "0"
Global $iSec = 0, $iMin = 0 ; TESTING VALUES - MOVE TO ZERO WHEN IT WORKS
Global $iHour = 0, $iDay = 0

$Timer = GUICreate("TIMER")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$stop1 = GUICtrlCreateButton("STOP", 10, 30, 50)
GUICtrlSetOnEvent(-1, "STOP")
$start1 = GUICtrlCreateButton("START", 110, 30, 50)
GUICtrlSetOnEvent(-1, "START")

$iDayDisplay = GUICtrlCreateButton($iDay, 26, 75, 50, 20)
GUICtrlSetState($iDayDisplay, $GUI_HIDE)

$iSecDisplay = GUICtrlCreateLabel($iSec, 58, 100, 12)
$cRightSideTime = GUICtrlCreateLabel(" : ", 42, 100, 6)
GUICtrlSetState($cRightSideTime, $GUI_HIDE)
$iMinDisplay = GUICtrlCreateLabel("", 26, 100, 12)
$cLeftSideTime = GUICtrlCreateLabel(" : ", 15, 100, 6)
GUICtrlSetState($cLeftSideTime, $GUI_HIDE)
$iHourDisplay = GUICtrlCreateLabel("", 0, 100, 12)

GUISetState(@SW_SHOW, $Timer)

; Just idle around
While 1
    ; STOP WATCH
    If $start_stop = 1 Then
        ;MsgBox(0,"$start_stop =", $start_stop)
        $stopper = 0
        StopWatch() ;stopWatcher()
    EndIf
    
    If $start_stop = 0 And $stopper = 0 Then
        $stopped = $iHour & ":" & $iMin & ":" & $iSec
        
        $msgReturn = MsgBox(4, "RESET", "Yes or No?")
        If $msgReturn = 6 Then
            MsgBox(0, "TEST 6", "YES")
            $iDay = ""
            $iHour = ""
            $iMin = ""
            $iSec = 0
            ClipPut($stopped)
            MsgBox(0, "Stopped", "Pressed the stop botton - $stopped = " & $stopped & @CRLF & "You Pressed Return - Your time will be on the clipboard. Just paste it where needed")
            GUICtrlSetData($iHourDisplay, $iHour)
            GUICtrlSetData($iMinDisplay, $iMin)
            GUICtrlSetData($iSecDisplay, $iSec)
            GUICtrlSetState($iDayDisplay, $GUI_HIDE)
        ElseIf $msgReturn = 7 Then
            ;MsgBox(0, "TEST 7", "NO")
        EndIf
        $stopper = 1
    EndIf
    Sleep(1000)
WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func STOP()
    $start_stop = 0
EndFunc   ;==>STOP

Func START()
    $start_stop = 1
    $iTimmerStarted = 1
EndFunc   ;==>START

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            ;MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            Exit
            
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
            ;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
            ;MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
    EndSelect
    
EndFunc   ;==>SpecialEvents

Func tester($text)
    MsgBox(0, $text, "DOING TESTS on " & $text)
EndFunc   ;==>tester

Func StopWatch()
    If $iTimmerStarted = 0 Then
        GUICtrlSetData($iSecDisplay, $0zero)
        ;If $iMin >= 1 Then GUICtrlSetData($iMinDisplay, $iMin)
        ;GUICtrlSetData($iHourDisplay, $00zero)
        $iTimmerStarted = 1
    EndIf
    _Count()
EndFunc   ;==>StopWatch

Func _Count()
    If GUICtrlRead($iSecDisplay) >= 0 And GUICtrlRead($iSecDisplay) < 59 Then
        GUICtrlSetData($iSecDisplay, $iSec)
        $iSec = GUICtrlRead($iSecDisplay) + 1
        GUICtrlSetData($iSecDisplay, $iSec)
    ElseIf GUICtrlRead($iSecDisplay) >= 59 Then
        $iSec = 0
        $iMin = $iMin + 1 ; what is the command to use to do this $iMin =+ 1 ???
        $iAddMin = 1
        GUICtrlSetData($iSecDisplay, $iSec)
    EndIf
    If $iMin >= 1 And $iAddMin = 1 Then
        GUICtrlSetData($iMinDisplay, $iMin)
        $iAddMin = 0
    ElseIf GUICtrlRead($iMinDisplay) >= 59 Then
        $iMin = 0
        $iHour = $iHour + 1
        $iAddHour = 1
        GUICtrlSetData($iSecDisplay, $iSec)
        GUICtrlSetData($iMinDisplay, $iMin)
    EndIf
    If $iHour >= 1 And $iAddHour = 1 Then
        GUICtrlSetData($iHourDisplay, $iHour)
        $iAddHour = 0
    ElseIf $iAddHour = 0 And $iHour = 24 Then
        GUICtrlSetState($iDayDisplay, $GUI_SHOW)
        $iDay = $iDay + 1
        GUICtrlSetData($iDayDisplay, $iDay)
        $iHour = 0
        $iMin = 0
        $iSec = 0
    EndIf
EndFunc   ;==>_Count

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites



I have the following so far - I have now wrote this 3 different times - and I know it still is not as good as it could be - I am looking for programming direction.

I am more interested in the Func _Count() area - as I drug the rest of it out of an existing program.

As you can see it is using the while statement to count the seconds - one of my tries was to add tenths of a second or hundreds, but I broke my code and had to start over - this is the start over code.

I would like to make it look like HH:MM:SS and maybe :100's if anyone can suggest a way of doing it.

I am not looking for someone to write it for me - I would like to know how to program it different or better. The Func _Count() part - any suggestions

CODE

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Global $start_stop = 0, $stopper = 1

Global $iTimmerStarted = 0, $iAddMin = 0, $iAddHour = 0

Global Const $00zero = "00", $0zero = "0"

Global $iSec = 0, $iMin = 0 ; TESTING VALUES - MOVE TO ZERO WHEN IT WORKS

Global $iHour = 0, $iDay = 0

$Timer = GUICreate("TIMER")

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")

GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$stop1 = GUICtrlCreateButton("STOP", 10, 30, 50)

GUICtrlSetOnEvent(-1, "STOP")

$start1 = GUICtrlCreateButton("START", 110, 30, 50)

GUICtrlSetOnEvent(-1, "START")

$iDayDisplay = GUICtrlCreateButton($iDay, 26, 75, 50, 20)

GUICtrlSetState($iDayDisplay, $GUI_HIDE)

$iSecDisplay = GUICtrlCreateLabel($iSec, 58, 100, 12)

$cRightSideTime = GUICtrlCreateLabel(" : ", 42, 100, 6)

GUICtrlSetState($cRightSideTime, $GUI_HIDE)

$iMinDisplay = GUICtrlCreateLabel("", 26, 100, 12)

$cLeftSideTime = GUICtrlCreateLabel(" : ", 15, 100, 6)

GUICtrlSetState($cLeftSideTime, $GUI_HIDE)

$iHourDisplay = GUICtrlCreateLabel("", 0, 100, 12)

GUISetState(@SW_SHOW, $Timer)

; Just idle around

While 1

; STOP WATCH

If $start_stop = 1 Then

;MsgBox(0,"$start_stop =", $start_stop)

$stopper = 0

StopWatch() ;stopWatcher()

EndIf

If $start_stop = 0 And $stopper = 0 Then

$stopped = $iHour & ":" & $iMin & ":" & $iSec

$msgReturn = MsgBox(4, "RESET", "Yes or No?")

If $msgReturn = 6 Then

MsgBox(0, "TEST 6", "YES")

$iDay = ""

$iHour = ""

$iMin = ""

$iSec = 0

ClipPut($stopped)

MsgBox(0, "Stopped", "Pressed the stop botton - $stopped = " & $stopped & @CRLF & "You Pressed Return - Your time will be on the clipboard. Just paste it where needed")

GUICtrlSetData($iHourDisplay, $iHour)

GUICtrlSetData($iMinDisplay, $iMin)

GUICtrlSetData($iSecDisplay, $iSec)

GUICtrlSetState($iDayDisplay, $GUI_HIDE)

ElseIf $msgReturn = 7 Then

;MsgBox(0, "TEST 7", "NO")

EndIf

$stopper = 1

EndIf

Sleep(1000)

WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func STOP()

$start_stop = 0

EndFunc ;==>STOP

Func START()

$start_stop = 1

$iTimmerStarted = 1

EndFunc ;==>START

Func SpecialEvents()

Select

Case @GUI_CtrlId = $GUI_EVENT_CLOSE

;MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Exit

Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE

;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Case @GUI_CtrlId = $GUI_EVENT_RESTORE

;MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

EndSelect

EndFunc ;==>SpecialEvents

Func tester($text)

MsgBox(0, $text, "DOING TESTS on " & $text)

EndFunc ;==>tester

Func StopWatch()

If $iTimmerStarted = 0 Then

GUICtrlSetData($iSecDisplay, $0zero)

;If $iMin >= 1 Then GUICtrlSetData($iMinDisplay, $iMin)

;GUICtrlSetData($iHourDisplay, $00zero)

$iTimmerStarted = 1

EndIf

_Count()

EndFunc ;==>StopWatch

Func _Count()

If GUICtrlRead($iSecDisplay) >= 0 And GUICtrlRead($iSecDisplay) < 59 Then

GUICtrlSetData($iSecDisplay, $iSec)

$iSec = GUICtrlRead($iSecDisplay) + 1

GUICtrlSetData($iSecDisplay, $iSec)

ElseIf GUICtrlRead($iSecDisplay) >= 59 Then

$iSec = 0

$iMin = $iMin + 1 ; what is the command to use to do this $iMin =+ 1 ???

$iAddMin = 1

GUICtrlSetData($iSecDisplay, $iSec)

EndIf

If $iMin >= 1 And $iAddMin = 1 Then

GUICtrlSetData($iMinDisplay, $iMin)

$iAddMin = 0

ElseIf GUICtrlRead($iMinDisplay) >= 59 Then

$iMin = 0

$iHour = $iHour + 1

$iAddHour = 1

GUICtrlSetData($iSecDisplay, $iSec)

GUICtrlSetData($iMinDisplay, $iMin)

EndIf

If $iHour >= 1 And $iAddHour = 1 Then

GUICtrlSetData($iHourDisplay, $iHour)

$iAddHour = 0

ElseIf $iAddHour = 0 And $iHour = 24 Then

GUICtrlSetState($iDayDisplay, $GUI_SHOW)

$iDay = $iDay + 1

GUICtrlSetData($iDayDisplay, $iDay)

$iHour = 0

$iMin = 0

$iSec = 0

EndIf

EndFunc ;==>_Count

Have you looked at TimerInit() and TimerDiff()? You set a variable to the current time tic with:

$TimeVar = TimerInit()oÝ÷ Ù8^*.ëmçb}÷«zwy¢+rݳ­«­¢+ØÀÌØíQ¥µ¥ôQ¥µÉ¥ ÀÌØíQ¥µYȤoÝ÷ Øéò¢ê趫²í¡ú®zËb¢z®¢×´ß¨

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks for your help - I will look into the function you suggested and try it out. I did find the answer to the adding $variable += 1 after I posted or this morning - all days are running together.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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