嗨,我有一个报告,用于vbscript
对我的字段进行逻辑分析。
该报告的字段为总分钟数,并具有较大的值,例如:1950分钟等。
我需要更新其他字段,以便将这些分钟转换为可读格式,例如4天2小时30分钟。我的工作时间是8个小时,因为这是我的劳动节。
因此16小时= 2天,依此类推。
现在我的逻辑是这样的:
' get the total minutes
total = sum(lateminutes)
' divide the minutes by 60 to get hours
hours = Int(total) / 60
' get the division difference and convert it to minutes
minutes = Round((hours - Int(hours)) * 60)
' convert my hours to days by dividing into 8 (8 hours per day)
days = Int(hours) / 8
if Int(days) > 0 then
text = Cstr(Int(days)) & " day(s)" & " "
end if
if Int(hours) > 0 then
text = text & Cstr(Int(hours)) & " hours" & " "
endif
if Int(minutes) > 0 then
text = text & minutes & " min"
endif
testfield.Text = text
但是我没有得到正确的结果,有任何线索吗?
用整数除法()计算较大的单位,然后从输入值中减去较大单位“使用”的分钟数。在代码中:
Option Explicit
Const cnMWD = 480 ' 8 * 60 mins in 8 hour working day
Const cnMWH = 60 ' 60 mins in 60 min working hour
Dim otp : otp = Array(0, "day(s)", 0, "hour(s)", 0, "mins")
Dim m, mm
For Each m In Array(59, 61, 479, 480, 485, 545, 2060)
mm = m
otp(0) = m \ cnMWD
m = m - otp(0) * cnMWD
otp(2) = m \ cnMWH
m = m - otp(2) * cnMWH
otp(4) = m
WScript.Echo mm, "=>", Join(otp)
Next
输出:
cscript 28798880.vbs
59 => 0 day(s) 0 hour(s) 59 mins
61 => 0 day(s) 1 hour(s) 1 mins
479 => 0 day(s) 7 hour(s) 59 mins
480 => 1 day(s) 0 hour(s) 0 mins
485 => 1 day(s) 0 hour(s) 5 mins
545 => 1 day(s) 1 hour(s) 5 mins
2060 => 4 day(s) 2 hour(s) 20 mins
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句