vb倒计时秒表的问题,求高手解决

最近我们要办一个演讲比赛,就琢磨着写一个秒表程序,我写了一个,但是毛病也出来了,一个是点击全部开始的时候,两个标签显示的时间不同步,还有一个就是这两个frame不能分别开... 最近我们要办一个演讲比赛,就琢磨着写一个秒表程序,我写了一个,但是毛病也出来了,一个是点击全部开始的时候,两个标签显示的时间不同步,还有一个就是这两个frame不能分别开始或暂停,因为只点击其中一个暂停的时候它确实暂停了,但是再让它开始就显示的是从另一个标签的时间开始了,有截图:求高手修改一下,代码如下:Dim Minute, Second As Long
Private Sub Command1_Click()
Minute = InputBox("输入分钟数", "倒计时时间")
Second = 60 * Minute
Label1.Caption = "计时时间为" & Minute & "分钟"
Label2.Caption = "计时时间为" & Minute & "分钟"
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True

End Sub

Private Sub Command2_Click()
Timer1.Interval = 1000
Timer1.Enabled = True

End Sub

Private Sub Command3_Click()
Timer1.Enabled = False

End Sub

Private Sub Command4_Click()
Timer2.Interval = 1000
Timer2.Enabled = True

End Sub

Private Sub Command5_Click()
Timer2.Enabled = False

End Sub

Private Sub Command6_Click()
Timer1.Interval = 1000
Timer2.Interval = 1000

Timer1.Enabled = True
Timer2.Enabled = True

End Sub

Private Sub Command7_Click()
Timer1.Enabled = False
Timer2.Enabled = False

End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False

Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False

End Sub

Private Sub Timer1_Timer()
If Second < 0 Then
Timer1.Enabled = False

Else
Label1.Caption = IIf(Second \ 3600 = 0, "00", IIf(Second \ 3600 < 10, "0" & Second \ 3600, Second \ 3600)) & ":" & IIf(Second \ 60 Mod 60 = 0, "00", IIf(Second \ 60 Mod 60 < 10, "0" & Second \ 60 Mod 60, Second \ 60 Mod 60)) & ":" & IIf(Second Mod 60 Mod 60 = 0, "00", IIf(Second Mod 60 Mod 60 < 10, "0" & Second Mod 60 Mod 60, Second Mod 60 Mod 60))
HScroll1.Value = (60 * Minute - Second) / (60 * Minute) * HScroll1.Max

Second = Second - 1
End If
End Sub
Private Sub Timer2_Timer()
If Second < 0 Then
Timer2.Enabled = False

Else
Label2.Caption = IIf(Second \ 3600 = 0, "00", IIf(Second \ 3600 < 10, "0" & Second \ 3600, Second \ 3600)) & ":" & IIf(Second \ 60 Mod 60 = 0, "00", IIf(Second \ 60 Mod 60 < 10, "0" & Second \ 60 Mod 60, Second \ 60 Mod 60)) & ":" & IIf(Second Mod 60 Mod 60 = 0, "00", IIf(Second Mod 60 Mod 60 < 10, "0" & Second Mod 60 Mod 60, Second Mod 60 Mod 60))
HScroll2.Value = (60 * Minute - Second) / (60 * Minute) * HScroll1.Max

Second = Second - 1
End If
End Sub
展开
 我来答
mijing2000
2011-05-27 · TA获得超过282个赞
知道小有建树答主
回答量:372
采纳率:0%
帮助的人:314万
展开全部
minute,second声明的全局变量吧
timer1停止,timer2继续在变化,timer1运行的时候,当然读入的是timer2中的second
还是把两个变量分开来吧,代码如下(你说的不同步问题,我测试下来没发现)
Dim Minute1, Second1, Minute2, Second2 As Long
Private Sub Command1_Click()
Minute1 = InputBox("输入分钟数", "倒计时时间")
Minute2 = Minute1
Second1 = 60 * Minute1
Second2 = Second1
Label1.Caption = "计时时间为" & Minute1 & "分钟"
Label2.Caption = "计时时间为" & Minute2 & "分钟"
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True

End Sub

Private Sub Command2_Click()
Timer1.Interval = 1000
Timer1.Enabled = True

End Sub

Private Sub Command3_Click()
Timer1.Enabled = False

End Sub

Private Sub Command4_Click()
Timer2.Interval = 1000
Timer2.Enabled = True

End Sub

Private Sub Command5_Click()
Timer2.Enabled = False

End Sub

Private Sub Command6_Click()
Timer1.Interval = 1000
Timer2.Interval = 1000

Timer1.Enabled = True
Timer2.Enabled = True

End Sub

Private Sub Command7_Click()
Timer1.Enabled = False
Timer2.Enabled = False

End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False

Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False

End Sub

Private Sub Timer1_Timer()
If Second1 < 0 Then
Timer1.Enabled = False

Else
Label1.Caption = IIf(Second1 \ 3600 = 0, "00", IIf(Second1 \ 3600 < 10, "0" & Second1 \ 3600, Second1 \ 3600)) & ":" & IIf(Second1 \ 60 Mod 60 = 0, "00", IIf(Second1 \ 60 Mod 60 < 10, "0" & Second1 \ 60 Mod 60, Second1 \ 60 Mod 60)) & ":" & IIf(Second1 Mod 60 Mod 60 = 0, "00", IIf(Second1 Mod 60 Mod 60 < 10, "0" & Second1 Mod 60 Mod 60, Second1 Mod 60 Mod 60))
HScroll1.Value = (60 * Minute1 - Second1) / (60 * Minute1) * HScroll1.Max

Second1 = Second1 - 1
End If
End Sub
Private Sub Timer2_Timer()
If Second2 < 0 Then
Timer2.Enabled = False

Else
Label2.Caption = IIf(Second2 \ 3600 = 0, "00", IIf(Second2 \ 3600 < 10, "0" & Second2 \ 3600, Second2 \ 3600)) & ":" & IIf(Second2 \ 60 Mod 60 = 0, "00", IIf(Second2 \ 60 Mod 60 < 10, "0" & Second2 \ 60 Mod 60, Second2 \ 60 Mod 60)) & ":" & IIf(Second2 Mod 60 Mod 60 = 0, "00", IIf(Second2 Mod 60 Mod 60 < 10, "0" & Second2 Mod 60 Mod 60, Second2 Mod 60 Mod 60))
HScroll2.Value = (60 * Minute2 - Second2) / (60 * Minute2) * HScroll1.Max

Second2 = Second2 - 1
End If
End Sub
megamine
2011-05-27
知道答主
回答量:5
采纳率:0%
帮助的人:0
展开全部
minute,second声明的全局变量吧
timer1停止,timer2继续在变化,timer1运行的时候,当然读入的是timer2中的second
还是把两个变量分开来吧,代码如下(你说的不同步问题,我测试下来没发现)
Dim Minute1, Second1, Minute2, Second2 As Long
Private Sub Command1_Click()
Minute1 = InputBox("输入分钟数", "倒计时时间")
Minute2 = Minute1
Second1 = 60 * Minute1
Second2 = Second1
Label1.Caption = "计时时间为" & Minute1 & "分钟"
Label2.Caption = "计时时间为" & Minute2 & "分钟"
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True

End Sub

Private Sub Command2_Click()
Timer1.Interval = 1000
Timer1.Enabled = True

End Sub

Private Sub Command3_Click()
Timer1.Enabled = False

End Sub

Private Sub Command4_Click()
Timer2.Interval = 1000
Timer2.Enabled = True

End Sub

Private Sub Command5_Click()
Timer2.Enabled = False

End Sub

Private Sub Command6_Click()
Timer1.Interval = 1000
Timer2.Interval = 1000

Timer1.Enabled = True
Timer2.Enabled = True

End Sub

Private Sub Command7_Click()
Timer1.Enabled = False
Timer2.Enabled = False

End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False

Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False

End Sub

Private Sub Timer1_Timer()
If Second1 < 0 Then
Timer1.Enabled = False

Else
Label1.Caption = IIf(Second1 \ 3600 = 0, "00", IIf(Second1 \ 3600 < 10, "0" & Second1 \ 3600, Second1 \ 3600)) & ":" & IIf(Second1 \ 60 Mod 60 = 0, "00", IIf(Second1 \ 60 Mod 60 < 10, "0" & Second1 \ 60 Mod 60, Second1 \ 60 Mod 60)) & ":" & IIf(Second1 Mod 60 Mod 60 = 0, "00", IIf(Second1 Mod 60 Mod 60 < 10, "0" & Second1 Mod 60 Mod 60, Second1 Mod 60 Mod 60))
HScroll1.Value = (60 * Minute1 - Second1) / (60 * Minute1) * HScroll1.Max

Second1 = Second1 - 1
End If
End Sub
Private Sub Timer2_Timer()
If Second2 < 0 Then
Timer2.Enabled = False

Else
Label2.Caption = IIf(Second2 \ 3600 = 0, "00", IIf(Second2 \ 3600 < 10, "0" & Second2 \ 3600, Second2 \ 3600)) & ":" & IIf(Second2 \ 60 Mod 60 = 0, "00", IIf(Second2 \ 60 Mod 60 < 10, "0" & Second2 \ 60 Mod 60, Second2 \ 60 Mod 60)) & ":" & IIf(Second2 Mod 60 Mod 60 = 0, "00", IIf(Second2 Mod 60 Mod 60 < 10, "0" & Second2 Mod 60 Mod 60, Second2 Mod 60 Mod
End If
End Sub !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式