Hi. This is my first post and i'm a newbie. I'm learning to use VB6 and i'm trying to create a simple alarm clock but having a type mismatch error. It seems that the input time does not match the clock time. i have here the code. Hope u can help me out.

Option Explicit
Dim StartTime As Variant
Dim EndTime As Variant
Dim ElapsedTime As Variant

Private Sub cmdEnd_Click()
'Find the ending time, compute the elapsed time
'Put both values in label boxes
EndTime = txtset.Text
lblEnd.Caption = Format(EndTime, "hh:mm:ss")

ElapsedTime = lblEnd.Caption - StartTime

If ElapsedTime = 0 Then

lblElapsed.BackColor = vbYellow
Beep
End If
lblElapsed.BackColor = vbRed
End Sub

Private Sub cmdExit_Click()
End
End Sub


Private Sub cmdStart_Click()
'Establish and print starting time
StartTime = Now
lblStart.Caption = Format(StartTime, "hh:mm:ss")
lblEnd.Caption = ""
lblElapsed.Caption = ""
End Sub


Private Sub Text1_Change()

End Sub

Private Sub timTimer1_Timer()
StartTime = Now
lblStart.Caption = Format(StartTime, "h:mm:ss ")

End Sub

Private Sub txtset_Change()
EndTime = txtset.Text
lblEnd.Caption = Format(EndTime, "hh:mm:ss")
End Sub

startime = now
starttime is a date and time

lblend.caption - starttime
you are trying to subtract a date from a time

to get the time of now use time instead of now
starttime = time

what do you need the timer for, why don't you put it in form_load event?

Sorry, I didn't look at your whole code before. There are some other problems

When you put a time into a label or text don't use format.
When you want to convert a string(label or text) into time then use timevalue function

The easiest way to do this is to use Date variables as your internal variables - never use variants unless you really really really have to (and then think again:) and only convert, using format, when you want to display.

Converting back and forth between text and date can be a pain. Also, use DateAdd and DateDiff functions to give you the alarm or stopwatch capabilities.

If you run your progam, it will break on the line where you calculate ElapsedTime. Look at the variables that that you're using. One is a date type, the other is a string. Therefore it can't do the calculation.

HTH
Martin

I manage to make it work. thanks to all the helped. managed to correct type mismatch. Also put in kepress commands. here is the code.

Public EndTime As String


Private Sub cmdEnd_Click()
lblStart.Caption = Time
lblEnd.Caption = EndTime

End Sub

Private Sub cmdExit_Click()
End
End Sub


Private Sub cmdStart_Click()
'Establish and print starting time
StartTime = Time
End Sub

Private Sub Form_Load()

End Sub

Private Sub timTimer1_Timer()
lblStart.Caption = Time
If Left(Time, Len(Time) - 6) = EndTime Then
Beep
lblElapsed.BackColor = vbRed
MsgBox "Its time!!!!"
txtset.Text = ""
End If
lblElapsed.BackColor = vbGreen
End Sub


Private Sub txtset_Change()
EndTime = txtset.Text
End Sub
Private Sub txtset_KeyPress(KeyAscii As Integer)
'Allow only number, minus sign, decimal point, backspace, return keys
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyMinus Or KeyAscii = vbKeyShiftMask + 58 Or KeyAscii = vbKeyDecPt Or KeyAscii = vbKeyBack Then
Exit Sub
ElseIf KeyAscii = vbKeyReturn Then
Call cmdEnd_Click
Else
KeyAscii = 0
End If
End Sub

This question has already been answered. Start a new discussion instead.