devxlogo

Determining If An Object Has Been Set

Determining If An Object Has Been Set

VB4 provides lots of new capabilities to use objects. Unfortunately,all of them require the object to be set beforehand, which isn’talways feasible. VB provides no way to see if an object has beenset. The only way of checking is to pass the object to a functionand attempt to access it. If it hasn’t been set, an error (number91) will occur.

For example:

 Public Function IsSomething(o As _        Object) As LongDim j As Long        Err.Clear        On Error Resume Next        If TypeOf o Is TextBox Then                j = 1                 'just a mindless test                'to see if we get an error        End If        If Err.Number = 91 Then        'error 91 = object not set                IsSomething = False                ElseIf Err.Number = 0 Then                        IsSomething = True                Else                        Err.Raise Err.Number                        'if some other error happened, raise it        End If        On Error GoTo 0End Function
See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist