Author Topic: [InForm] Stopwatch  (Read 23198 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
[InForm] Stopwatch
« on: June 17, 2018, 12:58:52 am »
A simple stopwatch using InForm for the interface. Code below provided for quick glimpse, as you'll need the complementary files in the zip attached to actually compile the program.

Code: QB64: [Select]
  1. ': This program uses
  2. ': InForm - GUI library for QB64 - Beta version 8
  3. ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
  4. ': https://github.com/FellippeHeitor/InForm
  5. '-----------------------------------------------------------
  6.  
  7. ': Controls' IDs: ------------------------------------------------------------------
  8. DIM SHARED Stopwatch AS LONG
  9. DIM SHARED TimeLB AS LONG
  10. DIM SHARED StartBT AS LONG
  11. DIM SHARED StopBT AS LONG
  12. DIM SHARED ListBox1 AS LONG
  13.  
  14. DIM SHARED start AS SINGLE, Running AS _BYTE
  15. DIM SHARED second AS INTEGER, minute AS INTEGER, hour AS INTEGER
  16.  
  17. ': External modules: ---------------------------------------------------------------
  18. '$INCLUDE:'InForm\InForm.ui'
  19. '$INCLUDE:'InForm\xp.uitheme'
  20. '$INCLUDE:'Stopwatch.frm'
  21.  
  22. ': Event procedures: ---------------------------------------------------------------
  23. SUB __UI_BeforeInit
  24.  
  25. SUB __UI_OnLoad
  26.     __UI_DefaultButtonID = StartBT
  27.  
  28. SUB __UI_BeforeUpdateDisplay
  29.     IF Running THEN
  30.         DIM theTime$
  31.  
  32.         elapsed = TIMER - start
  33.         IF elapsed >= 1 THEN
  34.             second = second + 1
  35.             elapsed = elapsed - 1
  36.             start = start + 1
  37.             IF second >= 60 THEN
  38.                 second = second - 60
  39.                 minute = minute + 1
  40.                 IF minute >= 60 THEN
  41.                     minute = minute - 60
  42.                     hour = hour + 1
  43.                 END IF
  44.             END IF
  45.         END IF
  46.  
  47.         hour$ = RIGHT$("00" + LTRIM$(STR$(hour)), 2)
  48.         min$ = RIGHT$("00" + LTRIM$(STR$(minute)), 2)
  49.         sec$ = RIGHT$("00" + LTRIM$(STR$(second)), 2)
  50.         elapsed$ = MID$(STR$(elapsed), INSTR(STR$(elapsed), ".") + 1) + "000"
  51.  
  52.         theTime$ = hour$ + ":" + min$ + ":" + sec$ + "," + LEFT$(elapsed$, 3)
  53.  
  54.         Caption(TimeLB) = theTime$
  55.     END IF
  56.  
  57. SUB __UI_BeforeUnload
  58.  
  59. SUB __UI_Click (id AS LONG)
  60.     SELECT CASE id
  61.         CASE Stopwatch
  62.  
  63.         CASE TimeLB
  64.  
  65.         CASE StartBT
  66.             IF Running THEN
  67.                 Caption(id) = "Start"
  68.                 Running = False
  69.                 Control(StopBT).Disabled = False
  70.                 Control(LapBT).Disabled = True
  71.             ELSE
  72.                 Caption(id) = "Pause"
  73.                 start = TIMER - elapsed
  74.                 Running = True
  75.                 Control(StopBT).Disabled = True
  76.                 Control(LapBT).Disabled = False
  77.             END IF
  78.         CASE LapBT
  79.             AddItem ListBox1, Caption(TimeLB)
  80.         CASE StopBT
  81.             second = 0
  82.             minute = 0
  83.             hour = 0
  84.             elapsed = 0
  85.             Caption(TimeLB) = "00:00:00,000"
  86.             ResetList ListBox1
  87.         CASE ListBox1
  88.  
  89.     END SELECT
  90.  
  91. SUB __UI_MouseEnter (id AS LONG)
  92.  
  93. SUB __UI_MouseLeave (id AS LONG)
  94.  
  95. SUB __UI_FocusIn (id AS LONG)
  96.  
  97. SUB __UI_FocusOut (id AS LONG)
  98.  
  99. SUB __UI_MouseDown (id AS LONG)
  100.  
  101. SUB __UI_MouseUp (id AS LONG)
  102.  
  103. SUB __UI_KeyPress (id AS LONG)
  104.  
  105. SUB __UI_TextChanged (id AS LONG)
  106.  
  107. SUB __UI_ValueChanged (id AS LONG)
  108.  
  109. SUB __UI_FormResized
  110.  
screenshot.png
* screenshot.png (Filesize: 16.68 KB, Dimensions: 812x247, Views: 722)
* Stopwatch.zip (Filesize: 73.57 KB, Downloads: 462)
« Last Edit: June 17, 2018, 12:24:21 pm by FellippeHeitor »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: [InForm] Stopwatch
« Reply #1 on: June 17, 2018, 02:21:08 am »
  • Best Answer
  • Looks nice Fellippe! :D
    if (Me.success) {Me.improve()} else {Me.tryAgain()}


    My Projects - https://github.com/AshishKingdom?tab=repositories
    OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

    FellippeHeitor

    • Guest
    Re: [InForm] Stopwatch
    « Reply #2 on: June 17, 2018, 10:36:41 am »
  • Best Answer
  • Thanks, Ashish. Let me know if you run it and if you find any issues.