Page 1 of 1

Timer in PB?

Posted: Tue Mar 08, 2005 6:09 pm
by mbecerra
I would like to know if PB has a timer function for executing code repeatidly after a certain amount of time has eclapsed.
Example:

Code: Select all

This code is in Liberty BASIC for demestration purposes only!

//create variable to hold how long the user has used the program for this scession
time1 = 0
//create variable to hold how long the program will run per scession
maxtime = 3

/create a timer that will execute the procedure CheckTrial() every 60 seconds
timer 60000, GoSub CheckTrial()

Procedure CheckTrial starts here
Sub CheckTrial()

//add 312 to the variable time1
time1 = time1 + 312

//if the user has used up all his time for this scession
if ((time1 / 312)  = maxtime)

//let the user know his time expired
MessageBox("Trial Peroid", "You time has expired", 0, 1, 0)

//and terminate the program
end

//Close If Statement
End If

//Code Procedure
End Sub

Posted: Tue Mar 08, 2005 7:24 pm
by Droopy
Lib puretools do this
-----------------------

Timer/Timing Overview
Timer





StartTimer()
Start a high resolution timer

EndTimer()
End a high resolution timer




Get Timer Info





GetMinTimerResolution()
Get the minimal timer resolution

GetMaxTimerResolution()
Get the maximal timer resolution

Posted: Tue Mar 08, 2005 7:40 pm
by thefool
or without lib just use winapi...:

SetTimer_() & killtimer_() read up on them or find examples in forum..
another way:

program your own... it requires more code but anyway it works..:

Code: Select all

Procedure mytimer()
  Repeat
  Delay(2000)  ;Sets how often timer is fired off
  MessageRequester("tim3r!","tim3r") ;Remember to press ok, else program wont make new msg box..
ForEver
EndProcedure

timer=CreateThread(@mytimer(),"") ;Timer is now created as a thread..
Delay(10000) ; Halt main program for 10 seconds
KillThread(timer) ;Kills the timer..

Posted: Tue Mar 08, 2005 8:38 pm
by Kale

Code: Select all

Global time1
time1 = 0
Global maxtime
maxtime = 3

Procedure CheckTrial()
    time1 = time1 + 312
    If ((time1 / 312)  = maxtime)
        MessageRequester("Trial Period", "You time has expired.")
        End
    EndIf
EndProcedure

If OpenWindow(1, 0, 0, 400, 300, #PB_Window_ScreenCentered, "Timer Demo")
    SetTimer_(WindowID(1), 1, 3000, @CheckTrial())
    Repeat
    Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Posted: Wed Mar 09, 2005 4:54 pm
by mbecerra
ok thank you.