Timer in PB?

Just starting out? Need help? Post your questions and find answers here.
mbecerra
User
User
Posts: 15
Joined: Mon Feb 28, 2005 4:59 am

Timer in PB?

Post 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
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post 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
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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..
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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
--Kale

Image
mbecerra
User
User
Posts: 15
Joined: Mon Feb 28, 2005 4:59 am

Post by mbecerra »

ok thank you.
Post Reply