Lionheart008
08-01-2010, 20:52
simple and good: timer countdown example with UI module :)
my 5 cent for today.
' 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
I hope this is 99 per cent perfect and in modern style ;)
best regards, frank
my 5 cent for today.
' 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
I hope this is 99 per cent perfect and in modern style ;)
best regards, frank