Click to See Complete Forum and Search --> : How can I creat a count down Clock with out using API (If it's need any!)
kourosh
Nov 13th, 1999, 01:46 PM
Hi, I wanted to know how to created a count down clock in a vbform. Forexample if you type 2 (meaning 2 hours) in a text box then you click start, the program start counting down the two hours. Can anybody help me to find a way do this but please don't say anything about API. I have no idea how to use API. Perhaps I should learn it soon. :)
PrOgGiE
Nov 13th, 1999, 02:24 PM
try using a Timer. You can use 2 labels one for the hour one for the minutes. Have the time decriment the minutes by one every minute and have the hours decrement when minutes reach zero.
christophe
Nov 14th, 1999, 11:16 AM
Here, play around with this code. It requires two text boxes, a command button to start countdown, and a timer control. Set the timer Interval to 1000. Good luck!
Private Sub Timer1_Timer()
Dim I As Integer
I = Val(Text2.Text)
Text2.Text = Format(I - 1, "00")
If I = 0 Then
Text2.Text = "59"
End If
End Sub
Private Sub Cmdtime_Click()
Timer1.Enabled = True
Text2.Text = "00"
If (Len(Text1.Text) = 1) Then
Text1.Text = "0" & Text1.Text
End If
If (Len(Text1.Text) = 1) And (Len(Text2.Text) = 2) Then
Text1.Text = "0" & Text1.Text
End If
If Text1.Text = "29" And Text2.Text = "50" Then
frmtimeup.Show
End If
Cmdtime.Enabled = False
Text1.Locked = True
Text2.Locked = True
End Sub
Private Sub Text2_Change()
Dim N As Integer
N = Val(Text1.Text)
If Text2.Text = "59" Then
Text1.Text = N - 1
End If
If Val(Text2.Text) = 0 And Val(Text1.Text) = 0 Then
Timer1.Enabled = False
Message = "Your time is up. "
buttonsandicons = vbOKOnly + vbInformation
Title = "Contdown"
MsgBox Message, buttonsandicons, Title
End If
Exit Sub
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.