|
-
Nov 15th, 2000, 05:07 PM
#1
Thread Starter
Frenzied Member
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
-
Nov 15th, 2000, 05:24 PM
#2
Junior Member
Have you tried IsObject Function?
-
Nov 15th, 2000, 05:32 PM
#3
Thread Starter
Frenzied Member
Thanks!
Nope.
But Thanks alot, I didnt even
know that existed!
-
Mar 9th, 2001, 04:38 PM
#4
New Member
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.
-
Mar 9th, 2001, 08:00 PM
#5
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|