|
-
Nov 13th, 1999, 02:46 PM
#1
Thread Starter
Hyperactive Member
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.
-
Nov 13th, 1999, 03:24 PM
#2
New Member
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.
-
Nov 14th, 1999, 12:16 PM
#3
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|