dcsimg
Results 1 to 5 of 5

Thread: Object not set?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Hello,

    I made some code to tell it a
    object variable was set that is
    pritty basic, but to tell it the
    object is set, it develops a error.

    how can I do this without a error?

    Code:
     
    Private Function ObjectSet(ByVal Obj As Object) As Boolean
        On Error GoTo ItsNotSet
        
    if obj = 1 then 
    'object set
    end if
    
        NotSet = true
        Exit Function
    
    ItsNotSet:
        NotSet = false
    End Function

  2. #2
    Junior Member
    Join Date
    Oct 2000
    Location
    Purgatory
    Posts
    31
    Have you tried IsObject Function?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Thanks!

    Nope.

    But Thanks alot, I didnt even
    know that existed!

  4. #4
    New Member
    Join Date
    Mar 2001
    Location
    Toronto, Ontario, Canada
    Posts
    1
    Unfortunately, isObject will not work for your situation.

    You want to check if your object variable actually points to a valid object.

    If you check the VB help under isObject, it says the following:

    "Returns a Boolean value indicating whether an identifier represents an object variable."

    So it only checks that the variable is defined as an object so since you used :

    (ByVal Obj As Obj)

    then isObject will always return true.

    The VB help also says:

    "Use error trapping to be sure that an object reference is valid."

    ... which sucks for me cause I need to check if an object is valid within my error handler and I don't want to put another error handler within my error handler.

    Hope that helps.

    Duff.

  5. #5
    New Member
    Join Date
    Mar 2001
    Location
    Redmond, WA
    Posts
    13

    Wink How to see if an object exists

    Here's what you need to do:

    Private Function ObjectSet(ByVal Obj As Object) As Boolean
    On Error GoTo ItsNotSet

    If (Obj Is Nothing) Then
          ObjectSet = False
    Else
          ObjectSet = True
    End If

    End Function

    If an object hasn't been initialized properly, it will be equal to Nothing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width