错误:类型不匹配。。
程序如下,一个定时闹钟程序,照课本敲的,但运行时错误是红色部分类型不匹配,求解。。
Option Explicit
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Dim msTime$
Private Sub CmdOk_Click()
Timer2.Enabled = True
Timer1.Enabled = True
LabShow.Caption = DateDiff("s", Format$(DT1.Value, "hh:mm:ss"), msTime$) Open (App.Path & "\Set.ini") For Output As #1
Print #1, DT1.Value
Close #1
End Sub
Private Sub Command2_Click()
Timer3.Enabled = False
Timer2.Enabled = False
Timer1.Enabled = False
Unload Me
End Sub
Private Sub Form_Load()
Dim Intext$
On Error GoTo ToExit
Open (App.Path & "\Set.ini") For Input As #1
Line Input #1, Intext
DT1.Value = Intext
Close #1
Exit Sub
ToExit:
Resume Next
End Sub
Private Sub Timer1_Timer()
TxtNow.Text = Time
End Sub
Private Sub Timer2_Timer()
On Error Resume Next
msTime$ = Format$(DT1.Value, "hh:mm:ss")
If msTime$ = "0:0:0" Then
LabShow.Caption = vbNullString
Else
If DateDiff("s", Format$(TxtNow.Text, "hh:mm:ss"), msTime$) >= 0 Then
LabShow.Caption = DateDiff("s", Format$(TxtNow.Text, "hh:mm:ss"), msTime$)
Else
LabShow.Caption = vbNullString
End If
End If
If LabShow.Caption = "0" Then
LabShow.Caption = "时间到"
Timer3.Enabled = True
Timer2.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()
Dim Musics As Long
Musics = CLng(600)
Beep Musics, 500
End Sub
[解决办法]
日期型,而不是字符串类型。改成:
DateDiff("s", CData(Format$(DT1.Value, "hh:mm:ss")), CDate(msTime$))