Private Sub Command1_Click()
If Command1.Caption = "暂停" Then
Command1.Caption = "继续"
Timer1.Enabled = False
Else
Command1.Caption = "暂停"
If Label1.Caption = "00:00:00:0" Then Form1.Tag = Timer
Timer1.Enabled = False
End If
End SubPrivate Sub Command2_Click()
这是设计一个计时器的程序代码:
Form1.Tag = Timer
Label1.Caption = "00:00:00:0"
End SubPrivate Sub Timer1_Timer()
m = Timer - Form1.Tag
n0 = (m * 10) Mod 10
m = Int(m)
n1 = Format(m Mod 60, "00,")
n2 = Format((m \ 60) Mod 60, "00:")
n3 = Format(m \ 3600, "00:")
Label1.Caption = n3 & n2 & n1 & n0
End Sub
运行的时候没有错误,可是一点开始,没有计时啊;是不是哪一个控件的属性没有设好啊?
再说,timer函数返回的不是从午夜到此时的秒数吗;Form1.Tag = Timer,m = Timer - Form1.Tag
怎么减啊?
小儿科,但是我自学,有点想通;;;;
请各位老师解释一下上面的程序;;;;;;;;;谢谢!

解决方案 »

  1.   

    '我觉得搂主的代码,好像太繁琐了,我改了一下。
    '随手写的,我机子刚镜像还原,还没装 VB ,代码没调试可能会错误。Dim StartTime As Date '定义一个全局变量保存起始时间。用 Me.Tag 属性保存虽然也行但是不好,因为它是 String 类型的。Private Sub Command1_Click()    If Timer1.Enabled Then
           Command1.Caption="继续"
        Else
           Command1.Caption="暂停"
        End If    Timer1.Enabled=Not Timer1.EnabledEnd SubPrivate Sub Command2_Click()
        '这是设计一个计时器的程序代码:
        StartTime=Now
        Label1.Caption = "00:00:00:0"
    End SubPrivate Sub Timer1_Timer()
        Label1.Caption = Format(Now-StartTime,"HH:MM:SS")
    End Sub
      

  2.   

    修改完的。把Timer1的ENABLED设为FALSE,Interval属性写个数Private Sub Command1_Click()
    If Command1.Caption = "暂停" Then
    Command1.Caption = "继续"
    Timer1.Enabled = False
    Else
    Command1.Caption = "暂停"
    If Label1.Caption = "00:00:00:0" Then Form1.Tag = Timer
    Timer1.Enabled = True
    End If
    End SubPrivate Sub Command2_Click()
    '这是设计一个计时器的程序代码:
    Form1.Tag = Timer
    Label1.Caption = "00:00:00:0"
    End SubPrivate Sub Timer1_Timer()
    m = Timer - Form1.Tag
    n0 = (m * 10) Mod 10
    m = Int(m)
    n1 = Format(m Mod 60, "00,")
    n2 = Format((m \ 60) Mod 60, "00:")
    n3 = Format(m \ 3600, "00:")
    Label1.Caption = n3 & n2 & n1 & n0
    End Sub