Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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

        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 0
End Function



Evan Dickinson
 
Comment and Contribute

 

 

 

 

 


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

 

 

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