Alpo, I try to keep up with the boards and did spot this article and I did incorporate it into the library already!
Thanks for saving me time!
Quote:
Microsoft has a daily article on "Howto" in VBS, called Hey, Scripting Guy! and the archives may help you in your quest.
I'm also all over this. I sent this message to them on Thursday. Note you'll recognize a converted CError() udf. Quote:
I'm probably not alone here by saying VBScript's error handling has me frustrated. Particularly, COM errors that vbscript doesn't seem to be able to interpret.
For instance, if I run this code snippet:
On Error Resume Next
Set objGroup = GetObject("WinNT://"& strComputer &"/"& strLocalDestinationGroup)
objGroup.Add "WinNT://"& strUserToAdd
wscript.echo err.number
wscript.echo err.description
and it fails because the user I'm trying to add already belongs to the target group, the err returned is:
-2147023518
and the descriiption is empty. Therein lies the problem.
HOWEVER, if I remove the On Error Resume Next, the compiler quits execution on the .Add method and correctly resolves the error to:
User is already a member of the target group.
So I'm using this function to convert the error to hex and back again into a standard System Error Code.
Function CError(lErr)
If lErr<0 Then lErr=HexToDec(Right(Hex(lErr),4)) End If
Err.Number = lErr
End function
Function HexToDec(strHex)
dim lngResult
dim intIndex
dim strDigit
dim intDigit
dim intValue
lngResult = 0
for intIndex = len(strHex) to 1 step -1
strDigit = mid(strHex, intIndex, 1)
intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
if intDigit >= 0 then
intValue = intDigit * (16 ^ (len(strHex)-intIndex))
lngResult = lngResult + intValue
else
lngResult = 0
intIndex = 0 ' stop the loop
end if
next
HexToDec = lngResult
End Function
Now, CError will properly convert -2147023518 to decimal 1378 which we can verify on this table: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes__1300-1699_.asp
The problem is this. If I try to err.raise= 1378, VBScript is clueless. Setting err.number = 1378 does help either.
How can I get VBScript to recognize and resolve these standard error codes to the proper description?
Any other error handling methodologies would be great help as well.
_________________________
-Jim
...the sort of general malaise that only the genius possess and the insane lament.