QTimer Examples
' Timer & OnKeyPress example for Rapid-Q by William Yu
' If no form is visible, Timer will not function.
' Not for PURE CONSOLE apps, but you're allowed to MIX.
DIM Timer1 AS QTimer, Timer2 AS QTimer
DIM Form AS QFORM
DIM Label1 AS QLABEL, Label2 AS QLABEL
DIM Label3 AS QLABEL
SUB TimerOver
Timer1.Interval = 100
I = I + 1
Label1.Caption = STR$(I)
END SUB
SUB Timer2Over
Timer2.Interval = 1000
J = J + 1
Label2.Caption = STR$(J)
END SUB
SUB KeyPressed (Key AS BYTE) '' Event returns one parameter
IF UCASE$(CHR$(Key)) = "Q" THEN
FORM.CLOSE
END IF
END SUB
I = 0 ' Undeclared variables are automatically global!
J = 0
FORM.CAPTION = "Timer Example"
FORM.WIDTH = 150
FORM.HEIGHT = 120
FORM.CENTER
Label1.Parent = Form
Label1.Caption = STR$(I)
Label1.Left = FORM.WIDTH/2
Label2.Parent = Form
Label2.Caption = STR$(J)
Label2.Left = FORM.WIDTH/2
Label2.Top = 40
Label3.Parent = Form
Label3.Caption = "Press 'Q' to quit'
Label3.Top = 75
Timer1.Interval = 100
Timer1.Enabled = 1 ' True
Timer1.OnTimer = TimerOver
Timer2.Interval = 1000
Timer2.Enabled = 1 ' True
Timer2.OnTimer = Timer2Over
FORM.OnKeyPress = KeyPressed
FORM.SHOWMODAL