大家帮我检查下vb60的倒计时程序?特别是"Label6.Caption = Str(Int(dd / (3600 * 24)))",为何出现语法错误?谢谢俄iPrivate Sub Form_click()
Dim starttime As String
Dim endtime As String
starttime = Now
endtime = CDate("2009-07-10   22:00:00")
Dim dd As Long
dd = DateDiff("s", starttime, endtime)
Label6.Caption = Str(Int(dd / (3600 * 24)))
Label7.Caption = Str(Int((dd - (Int(dd / (3600 * 24))) * (3600 * 24)) / 3600))
Label8.Caption = Str(Int((dd - (Int(dd / (3600 * 24))) * (3600 * 24) - ((dd - (Int(dd / (3600 * 24))) * (3600 * 24)) / 3600) * 3600) / 60))
Label9.Caption = Str(Int(dd - (Int(dd / (3600 * 24))) * (3600 * 24)) - (Int((dd - (Int(dd / (3600 * 24))) * (3600 * 24)) / 3600)) * 3600 - (Int((dd - (Int(dd / (3600 * 24))) * (3600 * 24) - ((dd - (Int(dd / (3600 * 24))) * (3600 * 24)) / 3600) * 3600) / 60)) * 60)
End Sub 

解决方案 »

  1.   

    首先理解一下 DateTime 型。它实际上是一个 Double 数字,整数部分表示 1899-12-30 以来的天数,小数(分数)部分表示一天内的时间,例如 0.5 表示正午。因此,两个日期时间相减,可直接得到相差的日时分秒,利用日期时间的格式函数就可以取出。这里的关键是日,需要转成其他整数类型,否则系统会解释成年月日。Private Sub Form_click()
    Dim starttime As Date
    Dim endtime As Date
    Dim d As Date, dd As Long
    starttime = Now
    endtime = CDate("2009-07-10  22:00:00")
    d = endtime - starttime
    dd = Int(d)
    Label6.Caption = dd
    Label7.Caption = Format(d, "H")
    Label8.Caption = Format(d, "n")
    Label9.Caption = Format(d, "s")
    End Sub
      

  2.   


    Private Sub Form_Click()
        Dim starttime As String
        Dim endtime As String
        Dim dd As Long
        
        starttime = Now
        endtime = CDate("2009-07-10  22:00:00")
        dd = DateDiff("s", starttime, endtime)
        Label6.Caption = Str(Int(dd / 60 / 60 / 24))
        Label7.Caption = Str(Int((dd - Val(Label6.Caption) * 60 * 60 * 24) / 3600))
        Label8.Caption = Str(Int((dd - Val(Label6.Caption) * 60 * 60 * 24 - Val(Label7.Caption) * 3600) / 60))
        Label9.Caption = Str(Int(dd - Val(Label6.Caption) * 60 * 60 * 24 - Val(Label7.Caption) * 3600 - Val(Label8.Caption) * 60))
    End Sub