Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need assistance with Error handling/trapping

Status
Not open for further replies.

bigragoo

MIS
May 28, 2008
3
US
Hi,
I am relatively new to VBScripting and have pieced together a script that works, but need some fine tuning. As a requirement if either the attribute doesn't reset or the file fails to copy an error code must be generated. I do not know how to do this and need some assistance. Here is an example of my code. Thanks

Code:
Option Explicit
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell:  Set objShell = CreateObject("WScript.Shell")
Dim strPath: strPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Dim objEnv: Set objEnv = objShell.Environment("Process")
Dim strCache, strMe, strCMD, objFile
strCache = objEnv.Item("WINDIR") & "\Installer\{AFA5AA71-989F-42E1-B3AF-BC6E135617F1}\"
strMe = Left(Replace(WScript.ScriptFullName,WScript.ScriptName,""), Len(Replace(WScript.ScriptFullName,WScript.ScriptName,""))-1)
strCMD = strMe & "\CiscoIPCommunicatorSetup.MST" & " "
If objFSO.FolderExists(strCache) = True Then
Set objFile = objFSO.GetFile(strCache & "CiscoIPCommunicatorSetup.MST")
objFile.Attributes = 0
If Err.Number <> 0 Then CleanEnv -1
objFSO.CopyFile strCMD, strCache, True
If Err.Number <> 0 Then CleanEnv -2
end if
CleanEnv 0
'----------------------------------------------------
Sub CleanEnv(intExitCode)
On Error Resume Next

Set objFSO = Nothing
Set objEnv = Nothing
Set objShell = Nothing

WScript.Quit intExitCode
End Sub
 
I'd put the On Error Resume Next instruction in the main program too.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, but that doesn't report the errors. I need a mechanism to report the errors.
 
Like this ?
Code:
...
If intExitCode <> 0 Then
  MsgBox "ERROR " & intExitCode
End If
WScript.Quit intExitCode
...
You may want to replace MsgBox with WScript.Echo

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That does not seem to help. Let's say I want to change the attribute from a 1 to a 0 but the file is open so I get a vbscript error. I would like to identify that error and display it in a msgbox.
 
Have a look at the Err.Number and Err.Description properties.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top