VB高手赐教!
一个倒计时的问题,想要在特定的时间,出现一个提示音。现在结束的时候会出现声音,要求在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
[解决办法]
- VB code
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 = TrueReturnEnd Sub
[解决办法]
直接计秒数不是更简单
- VB code
Option ExplicitPrivate m_Seconds As IntegerPrivate Sub Command3_Click() m_Seconds = 11 * 60 Label1 = TimeSerial(0, 0, m_Seconds) Command3.Enabled = False Timer1.Enabled = TrueEnd 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 IfEnd Sub