用VB实现:输入以秒为单位表示的时间,编写程序,将其换算成几日几时几分几秒
展开全部
Option Explicit
Dim Times As String, T As Long
Dim D As Integer, H As Integer, M As Integer, S As Integer
Private Sub Form_Load()
Form1.AutoRedraw = True
Times = InputBox("输入时间(单位:秒)", "输入", 123456)
T = Val(Times)
S = T Mod 60
T = T \ 60
M = T Mod 60
T = T \ 60
H = T Mod 24
D = T \ 24
Print Val(Times); "秒="; D; "日"; H; "时"; M; "分"; S; "秒"
End Sub
Dim Times As String, T As Long
Dim D As Integer, H As Integer, M As Integer, S As Integer
Private Sub Form_Load()
Form1.AutoRedraw = True
Times = InputBox("输入时间(单位:秒)", "输入", 123456)
T = Val(Times)
S = T Mod 60
T = T \ 60
M = T Mod 60
T = T \ 60
H = T Mod 24
D = T \ 24
Print Val(Times); "秒="; D; "日"; H; "时"; M; "分"; S; "秒"
End Sub
展开全部
Private Sub Form_Click()
Dim a As Long
a = Val(InputBox(""))
MsgBox a \ 86400 & "天" & (a Mod 86400) \ 3600 & "小时" & ((a Mod 86400) Mod 3600) \ 60 & "分钟" & (((a Mod 86400) Mod 3600) Mod 60) & "秒"
End Sub
Dim a As Long
a = Val(InputBox(""))
MsgBox a \ 86400 & "天" & (a Mod 86400) \ 3600 & "小时" & ((a Mod 86400) Mod 3600) \ 60 & "分钟" & (((a Mod 86400) Mod 3600) Mod 60) & "秒"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public Shared Function Test(ByVal Sec As Integer) As String
Dim OneMinute As Integer = 60 '每分钟60秒
Dim OneHour As Integer = 3600 '每小时3600秒
Dim OneDay As Integer = 86400 '每天86400秒
Dim iTemp As Integer '临时用
Dim iLast As Integer '剩余秒
Dim iReturn As String '返回值
'计算天
If Sec >= OneDay Then
iTemp = CInt(Sec / OneDay)
If OneDay * iTemp > Sec Then iTemp -= 1
iLast = CInt(Sec - OneDay * iTemp)
iReturn = iTemp.ToString & " 天 "
Else
iReturn = "0 天 "
End If
'计算小时
If iLast >= OneHour Then
iTemp = CInt(iLast / OneHour)
If OneHour * iTemp > iLast Then iTemp -= 1
iLast = CInt(iLast - OneHour * iTemp)
iReturn &= iTemp.ToString & " 小时 "
Else
iReturn &= " 0 小时 "
End If
'计算分
If iLast >= OneMinute Then
iTemp = CInt(iLast / OneMinute)
If OneMinute * iTemp > iLast Then iTemp -= 1
iLast = CInt(iLast - OneMinute * iTemp)
iReturn &= iTemp.ToString & " 分 "
Else
iReturn &= " 0 分"
End If
iReturn &= iLast.ToString & " 秒"
Return iReturn
End Function
Dim OneMinute As Integer = 60 '每分钟60秒
Dim OneHour As Integer = 3600 '每小时3600秒
Dim OneDay As Integer = 86400 '每天86400秒
Dim iTemp As Integer '临时用
Dim iLast As Integer '剩余秒
Dim iReturn As String '返回值
'计算天
If Sec >= OneDay Then
iTemp = CInt(Sec / OneDay)
If OneDay * iTemp > Sec Then iTemp -= 1
iLast = CInt(Sec - OneDay * iTemp)
iReturn = iTemp.ToString & " 天 "
Else
iReturn = "0 天 "
End If
'计算小时
If iLast >= OneHour Then
iTemp = CInt(iLast / OneHour)
If OneHour * iTemp > iLast Then iTemp -= 1
iLast = CInt(iLast - OneHour * iTemp)
iReturn &= iTemp.ToString & " 小时 "
Else
iReturn &= " 0 小时 "
End If
'计算分
If iLast >= OneMinute Then
iTemp = CInt(iLast / OneMinute)
If OneMinute * iTemp > iLast Then iTemp -= 1
iLast = CInt(iLast - OneMinute * iTemp)
iReturn &= iTemp.ToString & " 分 "
Else
iReturn &= " 0 分"
End If
iReturn &= iLast.ToString & " 秒"
Return iReturn
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询