我想通过vb的定时控件实现定时.报时的功能
           问:1.如何将时间(12:11:15)赋值给变量,而实现与time函数的校验.
              2.怎样才可以定时,在时间未到前,程序不会死循环.

解决方案 »

  1.   

    Dim timeTest As String
    Private Sub Form_Load()
        timeTest = "12:11:15"
        Timer1.Interval = 1000
        Timer1_Timer
    End SubPrivate Sub Timer1_Timer()
     If timeTest = CStr(Time()) Then
            MsgBox "时间到"
        End If
    End Sub
      

  2.   

    将Timer1的Interval 设置小一点,更准确。
      

  3.   

    不好意思,我还想问一点,怎样可以在一天内一次定时两三次呢,并且是通过text控件输入的
      

  4.   

    参考一下这个小程序或许有所帮助。
    Dim s As String
    Private Sub combo4_change()
    Label10.Caption = Combo4.Text
    End SubPrivate Sub Command1_Click()
     Label10.Caption = Combo4.Text
     If Combo1.Text = "" Or Combo2.Text = "" Or Label10.Caption = "" Or Combo3.Text = "" Then
          ret_val = MsgBox("请输入完整信息,不然我没法提醒你什么时候干什么。", vbExclamation + vbOKOnly + vbSystemModal, "守时小助手")
          If ret_val = 1 Then
             Command4.Enabled = False
          End If
     Else
             Label7.Caption = Combo1.Text & "点" & Combo2.Text & "分" & Combo3.Text & "秒"
             s = Label10.Caption
             ret_val = MsgBox("你确定的设置是正确的么?请注意时间制式为24小时制,时间设置不对,将无法及时提醒!", vbExclamation + vbOKCancel + vbSystemModal, "守时小助手")
         If ret_val = 2 Then
             Combo1.Text = ""
             Combo2.Text = ""
             Combo3.Text = ""
             Label10.Caption = ""
             Label7.Caption = ""
         Else
            Command4.Enabled = True
               Command2.Enabled = True
         End If
      End If
    End SubPrivate Sub Command2_Click()
    Combo1.Text = ""
    Combo2.Text = ""
    Combo3.Text = ""
    Label10.Caption = ""
    Label7.Caption = ""
    Command4.Enabled = False
    End SubPrivate Sub Command3_Click()
    Unload Me
    End SubPrivate Sub Command4_Click()
    Form1.Hide
    End SubPrivate Sub Form_Load()
    Label9.Caption = Date
    Label2.Caption = Time
    Command2.Enabled = False
    End SubPrivate Sub Timer1_Timer()
    Label9.Caption = Date
    Label2.Caption = Time
    If Time = Combo1.Text & ":" & Combo2.Text & ":" & Combo3.Text Then
        msg = "你好!我要提醒你," & "你告诉我:“" & s & "”"
        Style = vbExclamation + vbOKOnly + vbSystemModal
        Title = "守时小用助手提醒你了!"
        ret_val = MsgBox(msg, Style, Title)
        If trt_val = 1 Then
            Form1.Show
        End If
    End If
    End Sub