PDA

View Full Version : timer example :)



Lionheart008
30-03-2009, 11:22
hi all:)

have changed / done a timer example and would like to stop with the first button line the time (ok) and with the second button line (start again button) to stop the time and after start it again the time shouldn't run again from the 0 time beginning, but run further at the last stop... something like interims time...
anybody has an idea??? it's perhaps just simple I know, but I have changed the timervalue... in that case it should stop and get running for the next button click going on (increase) with the old value... but how??? - is not my day... ;(

ciao, Lionheart
ps: I don`t like such mondays... :roll:

Lionheart008
24-01-2010, 12:35
only some few days ago I thought about having a stop timer and intermediate timer for continuing the counter, but found this simple and easy way. it was simple. often I am thinking too complex or too complicated for such a little problem, perhaps you know this feeling too ;)
- basically I have used this simple timer example from sample folder and modified this one with second start/stop/timer functions. it's possible to stop and start and reset timer (first button line) and now with second button line to stop the timer after pushing start button but in this case to see how continue running counter from last stop position.

I am glad to find such a simple solution! that's took only some month :D


' Empty GUI script created on 01-24-2010 11:14:43 by franko (ThinAIR)
'--------------------------------------------------------------------
Uses "ui", "console"

%IDC_TIMER = 100
%IDC_LABEL = 200
%IDC_Start = 300
%IDC_Stop = 310
%IDC_Stop2 = 320
%IDC_Start2 = 330
%IDC_TIMER2 = 340
%IDC_LABEL2 = 350
%TIMER_DELAY = 10

'------------------------------------------------------------------------------
' Main function
'------------------------------------------------------------------------------
Function TBMain() As Long
Local hDlg As DWord

Dialog New 0, "Timer Example2 using CallBacks functions -> continue counting", -1, -1, 260, 80, %WS_OVERLAPPEDWINDOW To hDlg

Control Add Button, hDlg, %IDC_Start, "Start" , 10, 10, 50, 20
Control Add Button, hDlg, %IDC_Start2, "Start2" , 10, 40, 50, 20
Control Add Label , hDlg, %IDC_LABEL, "" , 90, 10, 55, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %SS_CENTERIMAGE Or %SS_CENTER
Control Add Label , hDlg, %IDC_LABEL2, "" , 90, 40, 55, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %SS_CENTERIMAGE Or %SS_CENTER
Control Add Button, hDlg, %IDC_Stop , "Stop" , 180, 10, 50, 20
Control Add Button, hDlg, %IDC_Stop2 , "Stop2" , 180, 40, 50, 20
Dialog Show Modal hDlg Call cbDialog
End Function

'------------------------------------------------------------------------------
' Callback procedure for main window
'------------------------------------------------------------------------------
CallBack Function cbDialog() As Long
Static TimerValue,TimerValue2 As Double '---Will be used to calculate timer values

Select Case CBMSG

Case %WM_INITDIALOG
'---Disable the stop button. At first timer is not active
Control Disable CBHNDL, %IDC_Stop
Control Disable CBHNDL, %IDC_Stop2

Case %WM_COMMAND

Select Case CBCTL
Case %IDC_Start
Control Disable CBHNDL, %IDC_Start
Control Enable CBHNDL, %IDC_Stop
TimerValue = 0 '---Set the time counter to zero
Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY

Case %IDC_Start2
Control Disable CBHNDL, %IDC_Start2
Control Enable CBHNDL, %IDC_Stop2
TimerValue2 += 0 '---> continue counter! :)
Dialog Set Timer CBHNDL, %IDC_TIMER2, %TIMER_DELAY

Case %IDC_Stop
Control Disable CBHNDL, %IDC_Stop
Control Enable CBHNDL, %IDC_Start
Dialog Kill Timer CBHNDL, %IDC_TIMER

Case %IDC_Stop2
Control Disable CBHNDL, %IDC_Stop2
Control Enable CBHNDL, %IDC_Start2
Dialog Kill Timer CBHNDL, %IDC_TIMER2
End Select

Case %WM_TIMER
Select Case CBWPARAM
Case %IDC_TIMER
TimerValue += 0.01
Control Set Text CBHNDL, %IDC_LABEL, Format$(TimerValue, "#0.00")

Case %IDC_TIMER2
TimerValue2 += 0.01
Control Set Text CBHNDL, %IDC_LABEL2, Format$(TimerValue2, "#0.00")
End Select
End Select
End Function



I show this example because I am thinking it's good fitted for beginners who are interested in callback functions and like sports or jogging :).

nice sunday, servus, franko lionheart