将 30 分钟当作一个周期来考虑:
Option Explicit
Dim a As IntegerPrivate Sub Command1_Click()
Timer1.Enabled = True
Label1.Caption = 20
Label1.ForeColor = vbRed
End SubPrivate Sub Timer1_Timer()
a = a + 1
If a < 20 Then
Label1.Caption = 20 - a
Label1.ForeColor = vbRed
ElseIf a < 30 Then
Label1.Caption = 30 - a
Label1.ForeColor = vbBlue
Else
a = 0
Label1.Caption = 20
Label1.ForeColor = vbRed
End If
End Sub
Option Explicit
Dim a As IntegerPrivate Sub Command1_Click()
Timer1.Enabled = True
Label1.Caption = 20
Label1.ForeColor = vbRed
End SubPrivate Sub Timer1_Timer()
a = a + 1
If a < 20 Then
Label1.Caption = 20 - a
Label1.ForeColor = vbRed
ElseIf a < 30 Then
Label1.Caption = 30 - a
Label1.ForeColor = vbBlue
Else
a = 0
Label1.Caption = 20
Label1.ForeColor = vbRed
End If
End Sub
尝试运行后蹦出对话框“编译错误: 过程声明与同名事件活过程的描述不匹配”
第四行:Private Sub Command1_Click() 被圈中
Dim a As IntegerPrivate Sub Command1_Click(Index As Integer)
Timer1.Enabled = True
Label1.Caption = 20
Label1.ForeColor = vbRed
End SubPrivate Sub Command2_Click(Index As Integer)
Timer1.Enabled = False
Label1.Caption = 20
Label1.ForeColor = vbRed
End Sub
Private Sub Timer1_Timer()
a = a + 1
If a < 20 Then
Label1.Caption = 20 - a
Label1.ForeColor = vbRed
If a = 19 Then
MsgBox "可以休息了!", vbExclamation
End If
ElseIf a < 30 Then
Label1.Caption = 30 - a
Label1.ForeColor = vbBlue
Else
a = 0
Label1.Caption = 20
MsgBox "该学习了!", vbCritical
Label1.ForeColor = vbRed
End If
End Sub可以基本满足需要。
但目前仍然有两个问题:
1.如何将时间格式改成"HH:MM:SS"的样式。
2.我希望在Msgbox出现时播放一个音乐,却不知如何实现。
恳请各位指导。