我在编一个闹钟程序,但是不知道哪里出错了,就是到时间不响铃
我用的是一个label,两个command,一个timer,程序如下
Dim tem
tem = AlarmTime
     AlarmTime = InputBox("输入响铃时间", "Alarm", AlarmTime)
     If AlarmTime = "" And tem = "" Then Exit Sub
     If AlarmTime = "" And tem <> "" Then AlarmTime = TEMP
     If AlarmTime = "" Then Exit Sub
     If Not IsDate(AlarmTime) Then
     MsgBox "the time you entered was not valid"
     Else
     AlarmTime = CVDate(AlarmTime)
     End If
--------------------------------------------------------------------------------
Static Alarmed As Integer
If Label1.Caption <> CStr(Time) Then
If Time = AlarmTime And Not Alarmed Then
   MsgBox ("提醒:" & vbCrLf & Time)
   Alarmed = True
   ElseIf Time < AlarmTime Then
   Alarmed = False
   End If
   Label1.Caption = Time
   End If
有什么问题?哪里出错了?我改怎么做?

解决方案 »

  1.   

    把 Time 转换成 Format(Time,'YYYY-MM-DD HH:MM:SS') 格式再比较。有可能是时间格式符没有完全匹配导致不能响铃。
      

  2.   

    If CStr(Time) = AlarmTime
      

  3.   

    VERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   3090
       ClientLeft      =   60
       ClientTop       =   450
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       ScaleHeight     =   3090
       ScaleWidth      =   4680
       StartUpPosition =   3  'Windows Default
       Begin VB.Timer Timer1 
          Interval        =   100
          Left            =   1110
          Top             =   1230
       End
       Begin VB.Label Label1 
          Caption         =   "Label1"
          Height          =   345
          Left            =   1560
          TabIndex        =   0
          Top             =   300
          Width           =   2295
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option Explicit
    Dim AlarmTime As String
    Dim tem
    Dim temp As StringPrivate Sub Form_Load()
        tem = AlarmTime
        AlarmTime = InputBox("输入响铃时间(时:分:秒 hh:mm:ss)", "Alarm", AlarmTime)
        If AlarmTime = "" And tem = "" Then Exit Sub
        If AlarmTime = "" And tem <> "" Then AlarmTime = temp
        If AlarmTime = "" Then Exit Sub
        If Not IsDate(AlarmTime) Then
            MsgBox "the time you entered was not valid"
        Else
            AlarmTime = CVDate(AlarmTime)
        End If
    End SubPrivate Sub Timer1_Timer()
        Static Alarmed As Integer
        If Label1.Caption <> CStr(Time) Then
            If Time = AlarmTime And Not Alarmed Then
                MsgBox ("提醒:" & vbCrLf & Time)
                Alarmed = True
            ElseIf Time < AlarmTime Then
                Alarmed = False
            End If
            Label1.Caption = Time
        End If
    End Sub
    --------------
    www.vicmiao.com
    努力就有美好时光!
      

  4.   

    if Time > cdate(AlarmTime) And Not Alarmed Thentem 和 temp 应该是一个东东was not valid -> is invalid
      

  5.   

    hn123(苗濤[www.vicmiao.com])  写得就能用啊楼主可以试一下
      

  6.   

    timer的interval 设成500输入:16:02:00
      

  7.   

    copy上边的程序试了下,可以弹出那个提醒窗口阿。