#Include #include #include #include #include #include #include #include Global $Log = "C:\Test\data.txt" Global $Timer Global $Time Global $Type = "" Global $hTitle = "Timer Test Application" ; Window title Global $hGUI Global $Timeout = (1) ;Create GUI $hGUI = GUICreate($hTitle, 400, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "Close_Main"); on exit call close function Opt("GUIOnEventMode", 1); allow Events Opt("GUICoordMode",1) $data = GUICtrlCreateInput('',150,20,100) $datalabel_1 = GUICtrlCreateLabel('Enter Test Data',30,23) $Button_1 = GUICtrlCreateButton ("OK", 190, 70, 50, 0, 0x0001) $Button_2 = GUICtrlCreateButton ("Exit", 250, 70, 50, 0) GUISetState () ; Run the GUI $Time = TimerInit(); initialize timer AdlibRegister ("Timer"); start timer While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Button_1 GLOBAL $collectdata = GUICtrlRead($data) MsgBox(0,'Timer Test Data','Data = ' & $collectdata) _FileWriteLog ($Log, "Creating Log File") ExitLoop Case $msg = $Button_2 Exit EndSelect WEnd Func Timer(); timer function and is called by Adlib every 250ms $new = TimerDiff ($time) $new = ($Timeout*60*1000)-$new; timeout from INI * 60 * 1000 = MINUTES $seconds = Round ($new/1000); round $newMin = Floor ($seconds/60); round DOWN to the nearest second $newSec = Mod ($seconds, 60) If $newSec < 10 Then $newSec = "0"&$newSec; if second is less than 10, use a 0 IE 5:05 instead of 5:5 Sleep (250); wait 250 mil to reduce flickering WinSetTitle ($hGUI,WinGetTitle ($hGUI,""),$hTitle&" Timer-"&$newMin&":"&$newSec); get the current window title, then append the timer Sleep (250); wait to reduce flickering If $Newmin < 1 and $Newsec < 1 then exit; if timer is 0:00 then exit ;NOTE, the pausing in the timer function will cause timer to jump one second periodically because it is losing 1/4 sec every cycle. Tradeoff is ok to reduce flicker EndFunc Func Close_Main(); on close Exit; exit script EndFunc