3 out of 18 rated this helpful - Rate this topic

Objects and Collections

The following table lists objects and collections in Visual Basic Scripting Edition (VBScript).

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
How to validate a properly created object (not null object)
I needed to know if an object that I require on the script was properly created. In order to do so, I end testing for a known property of my object. If the property exists, I assume the object is properly created/loaded. If it didn't, I assume something is wrong, this way I can issue a friendly message rather than the script error message. Here the code I use:

'
' Determines if the Object is properly instantiated.
Public Function MyObjectExist()
    On Error Resume Next
   
    ' Request the element that we need from MyObject (if there is an error it will resume next)
    MyObject.SpecificProperty
   
    If (0 = Err.Number) Then
        MyObjectExist = True
    Else
        MyObjectExist = False
    End If
End Function

JScript version:
//
// Determines if the Object is properly instantiated.
function MyObjectExist()
{
    // Request the element that we need from MyObject, make sure it is a valid object.
    if (null != MyObject.SpecificProperty) {
        return true;
    }
    return false;
}