Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Help with VBScript Timer

Reply
 
Old 08-28-2008   #1 (permalink)
Huskerboy


 
 

Help with VBScript Timer

I need to write a script that will time the download and upload of different
size files or folders to a NAS.
I am trying to put together data on upload and download times from different
loactions.
Here is what I have so far. It download the file but never finishes the timer.
Is there an easy way to do this.

Thanks in Advance

Dim WshShell,fso
Dim LOGFILENAME



Dim cnt

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const FILELOGPATH =
"c:\commonlog\applications\consolidated\download_timer.log"
Const ERRORLOGPATH =
"C:\commonlog\applications\consolidated\download_timer_error.log"
'-----------------------------
'CREATE OBJECTS FOR LATER USE
'-----------------------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set evar = wshshell.environment("Process")
Set WshNet = WScript.CreateObject("WScript.Network")

'To keep script from failing on error
'On Error Resume Next
'---------------------------
'Main
'---------------------------



Dim conn,conStr,conSoft,strSQL,rs,StartTime,c
'Open error log
Set ErrorLog = fso.OpenTextFile(ERRORLOGPATH,ForAppending,True)

StartTime = Timer
'------------------------

fso.CopyFolder "\\<servername>\<sharename>\<folder>", "c:\temp\"



'------------------------

If Err <>0 Then
msg = "An error occurred while trying to create the recordset:" & Err &
vbCrLf 'Create an understandable error msg
msg = msg & "Error number: " & Err & vbCrLf
msg = msg & "Description: " & Err.Description
Wscript.Echo msg
WshShell.Popup msg,3, "Error Pulling Records!",64
ErrorLog.writeline "<ScriptName>: " & Err.Description & " " & Now() & " "
& FormatNumber(Timer - StartTime,2)
Else
wscript.echo "Recordset created successfully."
ErrorLog.writeline "<ScriptName>: Completed Successfully " & Now() & " " &
FormatNumber(Timer - StartTime,2)
End If

My System SpecsSystem Spec
Old 08-28-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Help with VBScript Timer


"Huskerboy" <Huskerboy@xxxxxx> wrote in message
news:6BAC4816-933F-40FF-8732-F38CCDAA3558@xxxxxx
Quote:

>I need to write a script that will time the download and upload of
>different
> size files or folders to a NAS.
> I am trying to put together data on upload and download times from
> different
> loactions.
> Here is what I have so far. It download the file but never finishes the
> timer.
> Is there an easy way to do this.
>
> Thanks in Advance
>
> Dim WshShell,fso
> Dim LOGFILENAME
>
>
>
> Dim cnt
>
> Const ForReading = 1, ForWriting = 2, ForAppending = 8
> Const FILELOGPATH =
> "c:\commonlog\applications\consolidated\download_timer.log"
> Const ERRORLOGPATH =
> "C:\commonlog\applications\consolidated\download_timer_error.log"
> '-----------------------------
> 'CREATE OBJECTS FOR LATER USE
> '-----------------------------
> Set WshShell = WScript.CreateObject("WScript.Shell")
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set evar = wshshell.environment("Process")
> Set WshNet = WScript.CreateObject("WScript.Network")
>
> 'To keep script from failing on error
> 'On Error Resume Next
> '---------------------------
> 'Main
> '---------------------------
>
>
>
> Dim conn,conStr,conSoft,strSQL,rs,StartTime,c
> 'Open error log
> Set ErrorLog = fso.OpenTextFile(ERRORLOGPATH,ForAppending,True)
>
> StartTime = Timer
> '------------------------
>
> fso.CopyFolder "\\<servername>\<sharename>\<folder>", "c:\temp\"
>
>
>
> '------------------------
>
> If Err <>0 Then
> msg = "An error occurred while trying to create the recordset:" & Err &
> vbCrLf 'Create an understandable error msg
> msg = msg & "Error number: " & Err & vbCrLf
> msg = msg & "Description: " & Err.Description
> Wscript.Echo msg
> WshShell.Popup msg,3, "Error Pulling Records!",64
> ErrorLog.writeline "<ScriptName>: " & Err.Description & " " & Now() & " "
> & FormatNumber(Timer - StartTime,2)
> Else
> wscript.echo "Recordset created successfully."
> ErrorLog.writeline "<ScriptName>: Completed Successfully " & Now() & " " &
> FormatNumber(Timer - StartTime,2)
> End If
I also use the Timer function, use FormatNumber to format the difference
between the start and end times. This is the best way to time operations in
VBScript.

The code you included will halt if there is an error, so Err.Number will
never be non-zero. Assuming no errors, the information about success should
be logged. I would suggest (in part):
=======
Dim EndTimer

StartTime = Timer()

On Error Resume Next
fso.CopyFolder "\\<servername>\<sharename>\<folder>", "c:\temp\"

EndTime = Timer()

If (Err.Number <> 0) Then
msg = "An error occurred:" & vbCrLf
msg = msg & "Error number: " & Err.Number & vbCrLf
msg = msg & "Description: " & Err.Description
On Error GoTo 0
ErrorLog.writeline Err.Description & " " & Now() & " " &
FormatNumber(EndTime - StartTime, 2)
Else
On Error GoTo 0
ErrorLog.writeline "Completed Successfully " & Now() & " " &
FormatNumber(EndTime - StartTime,2)
End If
ErrorLog.Close
======
If there is an error, you don't want "On Error Resume Next" in affect or you
cannot troubleshoot. I assume above that the only error worth trapping is an
error on the copy statement. Your problem might even have been that you did
not close the log file. In my version I restore normal error handling as
soon as I can, after retrieving properties of the Err object.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to do No hang up VBScript (nohup for VBScript) VB Script
Egg Timer Vista General
RC2 Egg Timer Vista General
Egg timer on XP Vista General
Egg Timer Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46