Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 8, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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't always feasible. VB provides no way to see if an object has been set. The only way of checking is to pass the object to a function and attempt to access it. If it hasn't been set, an error (number 91) will occur.

For example:

Public Function IsSomething(o As _
        Object) As Long
Dim j As Long

        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
                        Err.Raise Err.Number
                        'if some other error happened, raise it
        End If

        On Error GoTo 0
End Function

Evan Dickinson
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date