搜索
您的当前位置:首页正文

时间计算器 高分

2008-09-29 来源:赴品旅游

有网友碰到这样的问题“时间计算器 高分”。小编为您整理了以下解决方案,希望对您有帮助:

解决方案1:

'建立一个text1
'4个按钮
' 结果会保存在程序目录下.resut.txt
'把下面代码复制进去就OK了.
'自己再美化下。
'---------------------------------------
Dim D, H, M, S
Dim D1, H1, M1, S1
Dim Z As Double
Dim J As String
Private Sub Command1_Click()
D = Day(Now)
H = Hour(Now)
M = Minute(Now)
S = Second(Now)
Command1.Enabled = False
Command2.Enabled = True
If Dir(App.Path & "\reust.txt") = "" Then
Open App.Path & "\reust.txt" For Output As #1
Close #1
Else
End If
Me.WindowState = 1
End Sub

Private Sub Command2_Click()
D = Day(Now) - D
H = Hour(Now) - H
M = Minute(Now) - M
S = Second(Now) - S
Z = (Val(S) + Val(M) * 60 + Val(H) * 3600 + Val(D) * 3600 * 24)
Text1.Text = Val(Z)
Command2.Enabled = False
Command3.Enabled = True
Dim Sj As String
Open App.Path & "\reust.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, Sj
Z = Z + Val(Sj)
Loop
Close #1
Open App.Path & "\reust.txt" For Output As #1
Print #1, Z
Close #1
MsgBox "统计并保存成功.", vbInformation, "提示."
MsgBox "本次共工作" & (Val(Z) - Val(Sj)) & "秒", vbInformation, "提示."
End Sub

Private Sub Command3_Click()
Z = Text1.Text
If Int(Val(Z)) < 59 Then
S1 = Int(Val(Z))
M1 = 0
H1 = 0
D1 = 0
MsgBox "本次共工作" & D1 & "天" & H1 & "小时" & M1 & "分" & S1 & "秒", vbInformation, "提示."
End If

If Int(Val(Z)) > 59 And Int(Val(Z)) < 3600 Then
S1 = (Int(Val(Z)) Mod 60)
M1 = Int(Val(Z / 60))
H1 = 0
D1 = 0
MsgBox "本次共工作" & D1 & "天" & H1 & "小时" & M1 & "分" & S1 & "秒", vbInformation, "提示."
End If

If Int(Val(Z)) > 3599 And Int(Val(Z)) < 800 Then
S1 = (Int(Val(Z)) Mod 60)
M1 = (Int(Val(Z / 60)) Mod 60)
H1 = Int(Val(Z / 3600))
D1 = 0
MsgBox "本次共工作" & D1 & "天" & H1 & "小时" & M1 & "分" & S1 & "秒", vbInformation, "提示."
End If

If Int(Val(Z)) > 86399 Then
S1 = (Int(Val(Z)) Mod 60)
M1 = (Val(Int(Val(Z / 60))) Mod 60)
H1 = Int(Val((Z / 3600) Mod 24))
D1 = Int(Val(Z / 800))
MsgBox "本次共工作" & D1 & "天" & H1 & "小时" & M1 & "分" & S1 & "秒", vbInformation, "提示."
End If
End Sub

Private Sub Command4_Click()
If Dir(App.Path & "\reust.txt") = "" Then
MsgBox "没有统计结果。", vbCritical, "Nothing"
Open App.Path & "\reust.txt" For Output As #1
Close #1
End If
Dim Sj As String
Open App.Path & "\reust.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, Sj
Z = Val(Sj)
Loop
Close #1
If Int(Val(Z)) < 59 Then
S1 = Int(Val(Z))
M1 = 0
H1 = 0
D1 = 0
MsgBox "至今为止共工作" & D1 & "天" & H1 & "小时" & M1 & "分" & S1 & "秒", vbInformation, "提示."
End If

If Int(Val(Z)) > 59 And Int(Val(Z)) < 3600 Then
S1 = (Int(Val(Z)) Mod 60)
M1 = Int(Val(Z / 60))
H1 = 0
D1 = 0
MsgBox "至今为止共工作" & D1 & "天" & H1 & "小时" & M1 & "分" & S1 & "秒", vbInformation, "提示."
End If

If Int(Val(Z)) > 3599 And Int(Val(Z)) < 800 Then
S1 = (Int(Val(Z)) Mod 60)
M1 = (Int(Val(Z / 60)) Mod 60)
H1 = Int(Val(Z / 3600))
D1 = 0
MsgBox "至今为止共工作" & D1 & "天" & H1 & "小时" & M1 & "分" & S1 & "秒", vbInformation, "提示."
End If

If Int(Val(Z)) > 86399 Then
S1 = (Int(Val(Z)) Mod 60)
M1 = (Val(Int(Val(Z / 60))) Mod 60)
H1 = Int(Val((Z / 3600) Mod 24))
D1 = Int(Val(Z / 800))
MsgBox "至今为止共工作" & D1 & "天" & H1 & "小时" & M1 & "分" & S1 & "秒", vbInformation, "提示."
End If
End Sub

Private Sub Form_Load()
Command2.Enabled = False
Command3.Enabled = False
Text1.Enabled = False
Text1.Text = ""
Command1.Caption = "开始工作"
Command2.Caption = "停止工作"
Command3.Caption = "统计本次工作"
Command4.Caption = "总计"
End Sub
'--------------------
'多给点分咯...#.

解决方案2:

你的问题实际上是两个:
一、计算时间间隔:
DateDiff 函数
DateDiff 函数可用来决定两个日期之间所指定的时间间隔数目。
二、时间累计

总代码如下:
Private Sub Command1_Click()
Dim d1 As Date, d2 As Date, sd As Long, delta As Long
Dim n As Integer, i As Integer
n = Val(InputBox("请输入要计算的天数"))
For i = 1 To n
d1 = CDate(InputBox("请输入第" & i & "天的开始时间(hh:mm)" & vbCrLf & " 如果开始日期与结束日期不同," & vbCrLf & " 则应该输入日期(dd hh:mm)"))
d2 = CDate(InputBox("请输入第" & i & "天的结束时间(hh:mm)" & vbCrLf & " 如果开始日期与结束日期不同," & vbCrLf & " 则应该输入日期(dd hh:mm)"))
delta = DateDiff("n", d1, d2)
Print i, delta \ 60; ":"; delta Mod 60
sd = sd + delta
Next i
Print "合计:"; sd \ 60; ":"; sd Mod 60
End Sub

Top