一个倒计时的问题,想要在特定的时间,出现一个提示音。现在结束的时候会出现声音,要求在5分或者10分钟的时候(变量),也出现一个提示音。倒计时的代码如下: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
        PlaySound "d:\3.WAV", ByVal 0&, &H20000 Or &H1        Command3.Enabled = True
    End If
  
    
End Sub

解决方案 »

  1.   

    上面的代码应该差不多。VB的定时器间隔在50ms~60000ms之间。
      

  2.   

    '注意:Timer1定时器设为60000,即1分钟
    '以下放在FORM或模块中申明
    public TotalSecond as integer
    TotalSecond = 30 '总时间为30分钟'Timer1的代码
    TotalSecond=TotalSecond-1'又过了一分钟
    if totalSecond = 10 ten
     PlaySound "d:\还有10分钟.WAV", ByVal 0&, &H20000 Or &H1'
    end if
    if totalSecond = 5 ten
     PlaySound "d:\还有5分钟.WAV", ByVal 0&, &H20000 Or &H1
    end if
      

  3.   


    Private Sub Timer1_Timer()
      'Count down loop
      Timer1.Enabled = False
      
      If (Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")) = "00:05:00" Then
          GoSub pro
          PlaySound "d:\3.WAV", ByVal 0&, &H20000 Or &H1
      ElseIf (Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")) = "00:10:00" Then
          GoSub pro
          PlaySound "d:\3.WAV", ByVal 0&, &H20000 Or &H1
      ElseIf (Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")) <> "00:00:00" Then
          GoSub pro
      Else
          'Turn off timer, set off alarm, and enable reset.
          GoSub pro
          PlaySound "d:\3.WAV", ByVal 0&, &H20000 Or &H1
          Timer1.Enabled = False
          Command3.Enabled = True
          Exit Sub
      End Ifpro:
       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
    ReturnEnd Sub
    没测试,你自己测试吧。
      

  4.   

    直接计秒数不是更简单
    Option ExplicitPrivate m_Seconds As IntegerPrivate Sub Command3_Click()
        m_Seconds = 11 * 60
        Label1 = TimeSerial(0, 0, m_Seconds)
        Command3.Enabled = False
        
        Timer1.Enabled = True
    End SubPrivate Sub Form_Load()
        Timer1.Enabled = False
        Timer1.Interval = 1000
        Command3.Caption = "倒计时"
    End SubPrivate Sub Timer1_Timer()
        Dim bNeedPlay As Boolean
        
        m_Seconds = m_Seconds - 1
        Label1 = TimeSerial(0, 0, m_Seconds)
        
        Select Case m_Seconds
            Case 300, 600
                bNeedPlay = True
            Case 0
                bNeedPlay = True
                
                Timer1.Enabled = False
                Command3.Enabled = True
        End Select
        
        If bNeedPlay Then
            PlaySound "d:\3.WAV", ByVal 0&, &H20000 Or &H1
        End If
    End Sub