大学体育舞蹈很尴尬:请教高手:怎样用vb编程实现......

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/04 23:15:12
怎样用vb编程实现离奥运会还有多少天?多少时?多少分?谢谢!

一楼写得有点麻烦
我给你个简单点的吧!需要一个时间控件和一个标签
时间控件的enabled 设为true
interva设为1000 也就是1秒执行一次这样就能动态现实
2008奥运会开始时间应该是8月15吧!

Private Sub Timer1_Timer()
Dim time As Long
Dim d, h, m, s As Integer
time = DateDiff("s", Now, #8/14/2008 12:00:00 PM#)
d = Int(time / 86400)
h = Int((time - d * 86400) / 3600)
m = Int((time - d * 86400 - h * 3600) / 60)
s = (time - d * 86400 - h * 3600 - m * 60)
L1.Caption = d & "天" & h & "小时" & m & "分" & s & "秒"
End Sub

看对不
Dim h, m, s As Integer

Private Sub Command1_Click()
Label1.Visible = False
Text1.Visible = True

If Command1.Caption = "Start" Then
Timer1.Enabled = True
Command1.Caption = "Stop"
Command2.Enabled = False
Else
Timer1.Enabled = False
Command1.Caption = "Start"
Command2.Caption = "Reset Time"
Command2.Enabled = True
End If
End Sub

Private Sub Command2_Click()
If Command2.Caption = "Reset Time" Then
Call again
Command1.Enabled = True

End If
End Sub

Private Sub Command3_Click()
a = MsgBox("Are you sure EXIT?")
End
End Sub

Private Sub Form_Load()
Cls
Text1.Text = ""
a = MsgBox("请按以下要求输入你要倒计时的时间")
h = Val(InputBox("请输入倒计时的,小时数,若无填0", "小时/输入", 0))
m = Val(InputBox("请输入倒计时的,分钟数,若无填0", "分钟/输入", 0))
s = Val(InputBox("请输入倒计时的,秒数,若无填0", "秒/输入", 0))
Label1.Caption = "你输入的时间是:" & Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & "如果没有错误请点击倒计时按纽"
Text1.Visible = False
End Sub

Sub again()
Cls
Text1.Text = ""
a = MsgBox("请按以下要求输入你要倒计时的时间")
h = Val(InputBox("请输入倒计时的,小时数,若无填0", "小时/输入", 0))
m = Val(InputBox("请输入倒计时的,分钟数,若无填0", "分钟/输入", 0))
s = Val(InputBox("请输入倒计时的,秒数,若无填0", "秒/输入", 0))
Label1.Caption = "你输入的时间是:" & Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & "如果没有错误请点击倒计时按纽"
Text1.Visible = False
Label1.Visible = True
End Sub

Private Sub Timer1_Timer()
If s > 0 Then
s = s - 1
End If
If s < 1 And m > 0 Then
m = m - 1
s = 60
End If
If m < 1 And s = 0 And h > 0 Then
h = h - 1
m = 60
End If
If h < 0 Then
h = 0
End If
If m < 0 Then
m = 0

End If

Text1.Text = Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00")
If h = 0 And m = 0 And s = 0 Then

Text1.Text = "Time's up!"
Command1.Caption = "Start"
Command1.Enabled = False
Timer1.Enabled = False
Command2.Enabled = True

End If
End Sub