Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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