|
-
Nov 22nd, 2010, 03:12 PM
#1
Thread Starter
New Member
Help returning NULL objects from VB6 Property
Ok I lived VB6 long ago, but am making an enhancment to a legacy VB6 app. The problem is I don't have the syntax quite right for returning objects from a class property that have no value.
In .NET this is trival, as returning the backing variable value and then having the caller check to see if it 'Is Nothing' works. In VB6 there (obviously) is no Return statement on Properties and the actual Return is assignment onto itself and I think this is where I am running into issues. The error I get is the famous "Object variable or With block varibale not set". So let me give the code example. This property referencing 'MyClass2' is within another class named MyClass1.
Property Example Code:
Private _mc2 As New MyClass2
Public Property Get mc2() A MyClass2
'This is where it bombs with the error mentioned above when checking if
'the value Is Nothing from the calling code
mc2 = _mc2
End Property
Public Property Let mc2(ByVal Value As MyClass1)
_mc2 = Value
End Property
Here would be an example calling code that causes the above to error:
'Say an intance of MyClass1 which contains the instance property. Assuming the mc2 Property has NO value (Is Nothing = True), I am going to test it like below:
Example calling code Code:
Dim mc1 As New MyClass1
If mc1.mc2 Is Nothing Then
End If
Any ideas on how I can test for a Property on a class that is actually an instance of a property, and check if it Is Nothing without getting the error? 
Thanks!
-
Nov 22nd, 2010, 03:29 PM
#2
Re: Help returning NULL objects from VB6 Property
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 22nd, 2010, 04:17 PM
#3
Thread Starter
New Member
Re: Help returning NULL objects from VB6 Property
Nevermind I figured this out.... I always forget to use the 'SET' statement when assigning objects in VB6. So the property needed to look like this:
Working Code Code:
Public Property Get mc2() A MyClass2
'Works
Set mc2 = _mc2
End Property
-
Nov 23rd, 2010, 04:29 AM
#4
Re: Help returning NULL objects from VB6 Property
As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).
Tags for this Thread
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
|