Results 1 to 2 of 2

Thread: timer countdown UI

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    timer countdown UI

    simple and good: timer countdown example with UI module
    my 5 cent for today.

    [code=thinbasic]' Empty GUI script created on 01-08-2010 19:24:04 by franko (ThinAIR)
    '--------- countdown timer example

    Uses "console", "ui"

    %myTimer = 100
    %myButton = 101

    Global hDlg As Long
    Global mode As String
    Global time As String
    Global minutes As Long
    Global seconds As Long
    Global mm As String
    Global ss As String

    Function tbmain() As Long
    Local t As String

    Dialog New 0, "Countdown Timer", 0, 0, 170, 45, %DS_CENTER Or %WS_CAPTION _
    Or %WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg
    Control Add Textbox, hDlg, %myTimer, "Enter minutes", 10, 10, 70, 14, %WS_BORDER
    Control Add Button, hDlg, %myButton, "Set", 90, 10, 70, 14
    Control Set Focus hDlg, %myTimer
    Control Send hDlg, %myTimer, %EM_SETSEL, 0, -1
    Dialog Show Modeless hDlg, Call MainProc

    mode = "wait"
    While mode = "wait"
    Dialog DoEvents
    Wend
    While mode = "run"
    Dialog DoEvents
    ss = RIGHT$(Time$, 2)
    While RIGHT$(Time$, 2) = ss
    Dialog DoEvents
    Wend
    ss = RIGHT$(Time$, 2)
    seconds = seconds - 1
    If seconds < 0 Then seconds = 59 : minutes = minutes - 1
    Control Set Text hDlg, Format$(minutes, "00") + ":" + Format$(seconds, "00"), t
    Control Set Text hDlg, %myTimer, Format$(minutes, "00") + ":" + Format$(seconds, "00")
    If (minutes = 0 And seconds = 0) Then
    Dialog Show State hDlg, %SW_RESTORE
    While mode = "run"
    Dialog DoEvents
    Wend
    End If
    Wend

    End Function

    CallBack Function MainProc()

    Select Case CBMSG
    Case %WM_COMMAND
    Select Case CBCTL
    Case %myButton
    If mode = "wait" Then
    Control Get Text hDlg, %myTimer To time
    If InStr(time, ":") = 0 Then
    minutes = Val(time)
    seconds = 1
    Else
    minutes = Val(LEFT$(time, InStr(time, ":") - 1))
    seconds = 1 + Val(Mid$(time, InStr(time, ":") + 1, 99))
    End If
    mode = "run"
    Control Set Text hDlg, %myButton, "Exit"
    Else
    mode = "exit"
    End If
    End Select
    Case %IDCANCEL
    mode = "exit"
    End Select

    End Function[/code]

    I hope this is 99 per cent perfect and in modern style

    best regards, frank
    Attached Images Attached Images
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: timer countdown UI

    Hi Frank,

    very nice example, good source for string manipulation studies.

    For simpler approach, have a look at DT_TimeSubSeconds, very interesting function


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. timer example :)
    By Lionheart008 in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 1
    Last Post: 24-01-2010, 12:35

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •