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!





Reply With Quote
