Culwatrnca11
asked on
script to show hours, minutes and seconds. Used to measure how long a certain batch file takes to run.
Modify the below to show hours, minutes and seconds for run time.Currently shows seconds only and I have to figure out the minutes, etc.. I want it to show hours, min and sec in the popup box when done.
Purpose shows how long it took to run BOs_main.bat
Purpose shows how long it took to run BOs_main.bat
Set WshShell = WScript.CreateObject("WScript.Shell")
sCmd = chr(34) & "c:\Final Reports\BOs_main.bat" & chr(34)
dtmStartTime = Timer
Return = WshShell.Run(sCmd, 1, true)
Wscript.Echo "The task completed in " & Round(Timer - dtmStartTime, 2) & " seconds."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
sCmd = chr(34) & "c:\Final Reports\BOs_main.bat" & chr(34)
dtmStartTime = Timer
Return = WshShell.Run(sCmd, 1, true)
s=Round(Timer - dtmStartTime, 2)
Hours = s \ 3600
Minutes = (s \ 60) Mod 60
Seconds = (s Mod 3600) Mod 60
Wscript.Echo "the script completed in " & Format(Hours, "00") & ":" & Format(Minutes, "00") & ":" & Format(Seconds, "00") & " That is: " & Hours & " hours " & Minutes & " minutes" & Seconds & " seconds"
sCmd = chr(34) & "c:\Final Reports\BOs_main.bat" & chr(34)
dtmStartTime = Timer
Return = WshShell.Run(sCmd, 1, true)
s=Round(Timer - dtmStartTime, 2)
Hours = s \ 3600
Minutes = (s \ 60) Mod 60
Seconds = (s Mod 3600) Mod 60
Wscript.Echo "the script completed in " & Format(Hours, "00") & ":" & Format(Minutes, "00") & ":" & Format(Seconds, "00") & " That is: " & Hours & " hours " & Minutes & " minutes" & Seconds & " seconds"
ASKER
how do i work either one of the suggestions into my existing VBA? What would my final code look like?
how do i work either one of the suggestions into my existing VBA?just add the function on top of your file
and call it whenever you need...
Function FormatTime(s)
Dim t, a, sec
sec = Int(s)
a = Array(CStr(Right("00" & Int(sec / 3600) Mod 24, 2)), CStr(Right("00" & Int(sec / 60) Mod 60, 2)), CStr(Right("00" & sec Mod 60, 2)))
FormatTime = Join(a, ":")
End Function
'your code here...
Wscript.Echo "The task completed in " & FormatTime(Timer - dtmStartTime) & " seconds."
ASKER
Arana,
That i get an error line 15, char 190, expected end of statement, Code 800A0401
That i get an error line 15, char 190, expected end of statement, Code 800A0401
I had a typo, already edited, try again.
ASKER
HainKurt,
your solution solved my issue. I have another issue that could be added to this code but i will submit a new issue.
Thank you Again.
your solution solved my issue. I have another issue that could be added to this code but i will submit a new issue.
Thank you Again.
I completly forgot VBscript doesnt have the format function, it would work for VBA,
so just replace FORMAT (Hours,"00") with Right("00" & Hours,2) , the same for minutes and seconds
so just replace FORMAT (Hours,"00") with Right("00" & Hours,2) , the same for minutes and seconds
Open in new window