1
1
Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2025-01-15 11:59:34 +00:00
InForm/examples/Stopwatch/Stopwatch.bas

224 lines
4.2 KiB
QBasic
Raw Normal View History

2023-06-15 21:58:12 +00:00
': This program uses
': InForm - GUI library for QB64 - v1.0
': Fellippe Heitor, 2016-2019 - fellippe@qb64.org - @fellippeheitor
': https://github.com/FellippeHeitor/InForm
'-----------------------------------------------------------
OPTION _EXPLICIT
2023-06-15 21:58:12 +00:00
': Controls' IDs: ------------------------------------------------------------------
DIM SHARED Stopwatch AS LONG
DIM SHARED TimeLB AS LONG
DIM SHARED StartBT AS LONG
DIM SHARED LapBT AS LONG
DIM SHARED StopBT AS LONG
DIM SHARED ListBox1 AS LONG
2023-06-15 21:58:12 +00:00
DIM SHARED start AS SINGLE, Running AS _BYTE
DIM SHARED second AS INTEGER, minute AS INTEGER, hour AS INTEGER
DIM SHARED elapsed AS SINGLE
2023-06-15 21:58:12 +00:00
': External modules: ---------------------------------------------------------------
'$INCLUDE:'../../InForm/InForm.bi'
2023-06-15 21:58:12 +00:00
'$INCLUDE:'Stopwatch.frm'
'$INCLUDE:'../../InForm/xp.uitheme'
'$INCLUDE:'../../InForm/InForm.ui'
2023-06-15 21:58:12 +00:00
': Event procedures: ---------------------------------------------------------------
SUB __UI_BeforeInit
2023-06-15 21:58:12 +00:00
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_OnLoad
2023-06-15 21:58:12 +00:00
__UI_DefaultButtonID = StartBT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_BeforeUpdateDisplay
IF Running THEN
DIM theTime$
2023-06-15 21:58:12 +00:00
elapsed = TIMER - start
IF elapsed >= 1 THEN
2023-06-15 21:58:12 +00:00
second = second + 1
elapsed = elapsed - 1
start = start + 1
IF second >= 60 THEN
2023-06-15 21:58:12 +00:00
second = second - 60
minute = minute + 1
IF minute >= 60 THEN
2023-06-15 21:58:12 +00:00
minute = minute - 60
hour = hour + 1
END IF
END IF
END IF
2023-06-15 21:58:12 +00:00
DIM hour$: hour$ = RIGHT$("00" + LTRIM$(STR$(hour)), 2)
DIM min$: min$ = RIGHT$("00" + LTRIM$(STR$(minute)), 2)
DIM sec$: sec$ = RIGHT$("00" + LTRIM$(STR$(second)), 2)
DIM elapsed$: elapsed$ = MID$(STR$(elapsed), INSTR(STR$(elapsed), ".") + 1) + "000"
2023-06-15 21:58:12 +00:00
theTime$ = hour$ + ":" + min$ + ":" + sec$ + "," + LEFT$(elapsed$, 3)
2023-06-15 21:58:12 +00:00
Caption(TimeLB) = theTime$
END IF
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_BeforeUnload
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_Click (id AS LONG)
SELECT CASE id
CASE Stopwatch
2023-06-15 21:58:12 +00:00
CASE TimeLB
2023-06-15 21:58:12 +00:00
CASE StartBT
IF Running THEN
2023-06-15 21:58:12 +00:00
Caption(id) = "Start"
Running = FALSE
Control(StopBT).Disabled = FALSE
Control(LapBT).Disabled = TRUE
ELSE
2023-06-15 21:58:12 +00:00
Caption(id) = "Pause"
start = TIMER - elapsed
Running = TRUE
Control(StopBT).Disabled = TRUE
Control(LapBT).Disabled = FALSE
END IF
CASE LapBT
2023-06-15 21:58:12 +00:00
AddItem ListBox1, Caption(TimeLB)
CASE StopBT
2023-06-15 21:58:12 +00:00
second = 0
minute = 0
hour = 0
elapsed = 0
Caption(TimeLB) = "00:00:00,000"
ResetList ListBox1
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_MouseEnter (id AS LONG)
SELECT CASE id
CASE Stopwatch
2023-06-15 21:58:12 +00:00
CASE TimeLB
2023-06-15 21:58:12 +00:00
CASE StartBT
2023-06-15 21:58:12 +00:00
CASE LapBT
2023-06-15 21:58:12 +00:00
CASE StopBT
2023-06-15 21:58:12 +00:00
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_MouseLeave (id AS LONG)
SELECT CASE id
CASE Stopwatch
2023-06-15 21:58:12 +00:00
CASE TimeLB
2023-06-15 21:58:12 +00:00
CASE StartBT
2023-06-15 21:58:12 +00:00
CASE LapBT
2023-06-15 21:58:12 +00:00
CASE StopBT
2023-06-15 21:58:12 +00:00
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_FocusIn (id AS LONG)
SELECT CASE id
CASE StartBT
2023-06-15 21:58:12 +00:00
CASE LapBT
2023-06-15 21:58:12 +00:00
CASE StopBT
2023-06-15 21:58:12 +00:00
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_FocusOut (id AS LONG)
SELECT CASE id
CASE StartBT
2023-06-15 21:58:12 +00:00
CASE LapBT
2023-06-15 21:58:12 +00:00
CASE StopBT
2023-06-15 21:58:12 +00:00
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_MouseDown (id AS LONG)
SELECT CASE id
CASE Stopwatch
2023-06-15 21:58:12 +00:00
CASE TimeLB
2023-06-15 21:58:12 +00:00
CASE StartBT
2023-06-15 21:58:12 +00:00
CASE LapBT
2023-06-15 21:58:12 +00:00
CASE StopBT
2023-06-15 21:58:12 +00:00
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_MouseUp (id AS LONG)
SELECT CASE id
CASE Stopwatch
2023-06-15 21:58:12 +00:00
CASE TimeLB
2023-06-15 21:58:12 +00:00
CASE StartBT
2023-06-15 21:58:12 +00:00
CASE LapBT
2023-06-15 21:58:12 +00:00
CASE StopBT
2023-06-15 21:58:12 +00:00
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_KeyPress (id AS LONG)
SELECT CASE id
CASE StartBT
2023-06-15 21:58:12 +00:00
CASE LapBT
2023-06-15 21:58:12 +00:00
CASE StopBT
2023-06-15 21:58:12 +00:00
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_TextChanged (id AS LONG)
SELECT CASE id
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_ValueChanged (id AS LONG)
SELECT CASE id
CASE ListBox1
2023-06-15 21:58:12 +00:00
END SELECT
END SUB
2023-06-15 21:58:12 +00:00
SUB __UI_FormResized
2023-06-15 21:58:12 +00:00
END SUB