Dim Hours As Integer
Dim Minutes As Integer
Dim Seconds As Integer
Dim Time As Date
Private Sub Mydisplay()
'This code is common to all three text boxes so I
'put it in it's own sub.
'Extract the numbers from the text boxes by using
'the Val() statement.
Hours = Val(Text1.Text)
Minutes = Val(Text2.Text)
Seconds = Val(Text3.Text)
'Convert variables to time format
Time = TimeSerial(Hours, Minutes, Seconds)
'Display the converted time variable in label 1
Label1.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")
End Sub
Private Sub Command1_Click()
'Start button - turn on timer and disable reset
'button
Timer1.Enabled = True
Command3.Enabled = False
End Sub
Private Sub Command2_Click()
'Pause button - temporarily stop timer and enable
'reset button. You can restart countdown by clicking
'the start button. Or reset the time by clicking
'the reset button.
Timer1.Enabled = False
Command3.Enabled = True
End Sub
Private Sub Command3_Click()
'Reset button - reset all varibles and text boxes
'to nothting.
Hours = 0
Minutes = 0
Seconds = 0
Time = 0
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text1.SetFocus 'put curser in the hour text box
End Sub
Private Sub Command4_Click()
'Exit button - end program and clear varibles
End
End Sub
Private Sub Form_Load()
'Center form on screen.
Form1.Top = (Screen.Height - Form1.Height) / 2
Form1.Left = (Screen.Width - Form1.Width) / 2
'Set timer interval and varibles
Timer1.Interval = 1000
Hours = 0
Minutes = 0
Seconds = 0
Time = 0
End Sub
Private Sub Text1_Change()
'Call Mydisplay sub to display text box data
Mydisplay
End Sub
Private Sub Text2_Change()
'Call Mydisplay sub to display text box data
Mydisplay
End Sub
Private Sub Text3_Change()
'Call Mydisplay sub to display text box data
Mydisplay
End Sub
Private Sub Timer1_Timer()
'Count down loop
Timer1.Enabled = False
If (Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")) <> "00:00:00" Then 'Counter to continue loop until 0
Time = DateAdd("s", -1, Time)
Label1.Visible = False
Label1.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")
Label1.Visible = True
Timer1.Enabled = True
Else
'Turn off timer, set off alarm, and enable reset.
Timer1.Enabled = False
Beep
Beep
Command3.Enabled = True
End If
End Sub
Using the code above im able to make it work but you have to input the hh/mm/ss manually instead i want to already have a set time placed in the code so as soon as i hit start the countdown begins on the label i would have right under the command button. For example one of the times ill be using will be 2hrs. so when i click the command button i want the numbers to show up on the label and automatically begin it's 2hr countdown.