Classes within Classes 
Author Message
 Classes within Classes

I'm having problems referencing a class defined within another.  When I try
to get a property from the subclass, I get an error that reads: "Object
variable or With block variable not set (91)" .  What's going on?  Please
see code below.

Thanks in advance,

Craig Buchanan, President
Cogniza, Inc.
Seagate Software Partner
http://www.*-*-*.com/

+1.612.824.5858

*************code*****************

***Class CBorrower***
Private oCB As CCoborrower

Public Property Get CB() As CCoborrower
    CB = oCB
End Property

***Class Coborrower***
Public Property Get FirstName() As Variant
    FirstName = "Craig"
End Property

***Regular Module***
Sub Main
    dim oB as CBorrower

    set oB = new CBorrower
    debug.print oB.CB.FirstName

End Sub



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes

How are you exposing the sub-class?

Quote:

> I'm having problems referencing a class defined within another.  When I try
> to get a property from the subclass, I get an error that reads: "Object
> variable or With block variable not set (91)" .  What's going on?  Please
> see code below.

> Thanks in advance,

> Craig Buchanan, President
> Cogniza, Inc.
> Seagate Software Partner
> http://www.cogniza.com

> +1.612.824.5858

> *************code*****************

> ***Class CBorrower***
> Private oCB As CCoborrower

> Public Property Get CB() As CCoborrower
>     CB = oCB
> End Property

> ***Class Coborrower***
> Public Property Get FirstName() As Variant
>     FirstName = "Craig"
> End Property

> ***Regular Module***
> Sub Main
>     dim oB as CBorrower

>     set oB = new CBorrower
>     debug.print oB.CB.FirstName

> End Sub



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
Hi Craig,

Quote:
>Public Property Get CB() As CCoborrower
>    CB = oCB
>End Property

I would rewrite this like.

Public Property Get CB() As CCoborrower
    If oCB is nothing then
        Set oCB = New CCoborrower
    End If
    CB = oCB
End Property

Basicly I think you need to instantiate your object before returning it from
the property.

Rob

Quote:

>I'm having problems referencing a class defined within another.  When I try
>to get a property from the subclass, I get an error that reads: "Object
>variable or With block variable not set (91)" .  What's going on?  Please
>see code below.

>Thanks in advance,

>Craig Buchanan, President
>Cogniza, Inc.
>Seagate Software Partner
>http://www.cogniza.com

>+1.612.824.5858

>*************code*****************

>***Class CBorrower***
>Private oCB As CCoborrower

>Public Property Get CB() As CCoborrower
>    CB = oCB
>End Property

>***Class Coborrower***
>Public Property Get FirstName() As Variant
>    FirstName = "Craig"
>End Property

>***Regular Module***
>Sub Main
>    dim oB as CBorrower

>    set oB = new CBorrower
>    debug.print oB.CB.FirstName

>End Sub



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes

Quote:

> I'm having problems referencing a class defined within another.  When I try
> to get a property from the subclass, I get an error that reads: "Object
> variable or With block variable not set (91)" .  What's going on?  Please
> see code below.
> <snip>
> *************code*****************

> ***Class CBorrower***
> Private oCB As CCoborrower

> Public Property Get CB() As CCoborrower
>     CB = oCB
> End Property

> ***Class Coborrower***
> Public Property Get FirstName() As Variant
>     FirstName = "Craig"
> End Property

> ***Regular Module***
> Sub Main
>     dim oB as CBorrower

>     set oB = new CBorrower
>     debug.print oB.CB.FirstName

> End Sub

Where do you set oCB?  Anywhere?  Do you have an Initialize function for your
CoBorrower?

--
-------------------------
| gHaD (Aaron Robinson) |
|MJM-PC Solutions, Inc. |
|      Chicago, IL      |
-------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
I added this code.  I now get an error "Invalid use of object" on the line

"If oCB is nothing then" at the "nothing" word.

Ideas?

Craig

Quote:

>Hi Craig,

>>Public Property Get CB() As CCoborrower
>>    CB = oCB
>>End Property

>I would rewrite this like.

>Public Property Get CB() As CCoborrower
>    If oCB is nothing then
>        Set oCB = New CCoborrower
>    End If
>    CB = oCB
>End Property

>Basicly I think you need to instantiate your object before returning it
from
>the property.

>Rob


>>I'm having problems referencing a class defined within another.  When I
try
>>to get a property from the subclass, I get an error that reads: "Object
>>variable or With block variable not set (91)" .  What's going on?  Please
>>see code below.

>>Thanks in advance,

>>Craig Buchanan, President
>>Cogniza, Inc.
>>Seagate Software Partner
>>http://www.cogniza.com

>>+1.612.824.5858

>>*************code*****************

>>***Class CBorrower***
>>Private oCB As CCoborrower

>>Public Property Get CB() As CCoborrower
>>    CB = oCB
>>End Property

>>***Class Coborrower***
>>Public Property Get FirstName() As Variant
>>    FirstName = "Craig"
>>End Property

>>***Regular Module***
>>Sub Main
>>    dim oB as CBorrower

>>    set oB = new CBorrower
>>    debug.print oB.CB.FirstName

>>End Sub



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
Through the CBorrower class.  Is that your question?

Craig

Quote:

>How are you exposing the sub-class?


>> I'm having problems referencing a class defined within another.  When I
try
>> to get a property from the subclass, I get an error that reads: "Object
>> variable or With block variable not set (91)" .  What's going on?  Please
>> see code below.

>> Thanks in advance,

>> Craig Buchanan, President
>> Cogniza, Inc.
>> Seagate Software Partner
>> http://www.cogniza.com

>> +1.612.824.5858

>> *************code*****************

>> ***Class CBorrower***
>> Private oCB As CCoborrower

>> Public Property Get CB() As CCoborrower
>>     CB = oCB
>> End Property

>> ***Class Coborrower***
>> Public Property Get FirstName() As Variant
>>     FirstName = "Craig"
>> End Property

>> ***Regular Module***
>> Sub Main
>>     dim oB as CBorrower

>>     set oB = new CBorrower
>>     debug.print oB.CB.FirstName

>> End Sub



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
I don't have an initialize function for the CBorrower class.  At the
suggestion of Robert Rodgers, I modified the "Get CB" property to read

Public Property Get CB() As CCoborrower
    If oCB = Nothing Then
        Set oCB = New CCoborrower
    End If
    CB = oCB
End Property

I now get an error on the "nothing" word reading "Invalid use of object".

Ideas?

Craig

Quote:


>> I'm having problems referencing a class defined within another.  When I
try
>> to get a property from the subclass, I get an error that reads: "Object
>> variable or With block variable not set (91)" .  What's going on?  Please
>> see code below.
>> <snip>

>> *************code*****************

>> ***Class CBorrower***
>> Private oCB As CCoborrower

>> Public Property Get CB() As CCoborrower
>>     CB = oCB
>> End Property

>> ***Class Coborrower***
>> Public Property Get FirstName() As Variant
>>     FirstName = "Craig"
>> End Property

>> ***Regular Module***
>> Sub Main
>>     dim oB as CBorrower

>>     set oB = new CBorrower
>>     debug.print oB.CB.FirstName

>> End Sub

>Where do you set oCB?  Anywhere?  Do you have an Initialize function for
your
>CoBorrower?

>--
>-------------------------
>| gHaD (Aaron Robinson) |
>|MJM-PC Solutions, Inc. |
>|      Chicago, IL      |
>-------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
Craig,

This is a cut and paste from one application I wrote.  It works fine for
me....   Maybe you need to preface your object with the cls name where it
exists?  Sorry I can't be of more help.

Good luck
Rob

Private moOuiGen                        As ouiGeneral.clsOuiGeneral

Public Property Get oOuiGen() As ouiGeneral.clsOuiGeneral
On Error GoTo ErrHndlr
    If moOuiGen Is Nothing Then
        Set moOuiGen = New ouiGeneral.clsOuiGeneral
    End If

    Set oOuiGen = moOuiGen

Exit Property

ErrHndlr:

    sErrDesc = Err.Description
    nErrNum = Err.Number: sSource = Err.Source
    With basglobaldefs.oErrHandler
            .Number = nErrNum
            .Description = sErrDesc
            .Localize = False
            .Module = mkMODULE_NAME$
            .Proc = "oOuiGen"
            .Step = msStepName
            .SeverityLevel = Fatal
            .Source = sSource
            .WriteToLog = False
            Call .Raise
        End With

End Property

Quote:

>I added this code.  I now get an error "Invalid use of object" on the line

>"If oCB is nothing then" at the "nothing" word.

>Ideas?

>Craig


>>Hi Craig,

>>>Public Property Get CB() As CCoborrower
>>>    CB = oCB
>>>End Property

>>I would rewrite this like.

>>Public Property Get CB() As CCoborrower
>>    If oCB is nothing then
>>        Set oCB = New CCoborrower
>>    End If
>>    CB = oCB
>>End Property

>>Basicly I think you need to instantiate your object before returning it
>from
>>the property.

>>Rob


>>>I'm having problems referencing a class defined within another.  When I
>try
>>>to get a property from the subclass, I get an error that reads: "Object
>>>variable or With block variable not set (91)" .  What's going on?  Please
>>>see code below.

>>>Thanks in advance,

>>>Craig Buchanan, President
>>>Cogniza, Inc.
>>>Seagate Software Partner
>>>http://www.cogniza.com

>>>+1.612.824.5858

>>>*************code*****************

>>>***Class CBorrower***
>>>Private oCB As CCoborrower

>>>Public Property Get CB() As CCoborrower
>>>    CB = oCB
>>>End Property

>>>***Class Coborrower***
>>>Public Property Get FirstName() As Variant
>>>    FirstName = "Craig"
>>>End Property

>>>***Regular Module***
>>>Sub Main
>>>    dim oB as CBorrower

>>>    set oB = new CBorrower
>>>    debug.print oB.CB.FirstName

>>>End Sub



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes

Quote:

> I don't have an initialize function for the CBorrower class.  At the
> suggestion of Robert Rodgers, I modified the "Get CB" property to read

> Public Property Get CB() As CCoborrower
>     If oCB = Nothing Then
>         Set oCB = New CCoborrower
>     End If
>     CB = oCB
> End Property

> I now get an error on the "nothing" word reading "Invalid use of object".

> Ideas?

Something can't equal Nothing.  Nothing is kinduv a state for an object.  It can
*be* nothing, though.  Refer back to Robert's syntax.....     If oCB Is Nothing
Then

--
HTH
-------------------------
| gHaD (Aaron Robinson) |
|MJM-PC Solutions, Inc. |
|      Chicago, IL      |
-------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
of course, Robert suggested you use:

if ocb is nothing

and you say you used

if ocb = nothing

which causes your error . . .

Quote:

> I don't have an initialize function for the CBorrower class.  At the
> suggestion of Robert Rodgers, I modified the "Get CB" property to read

> Public Property Get CB() As CCoborrower
>     If oCB = Nothing Then
>         Set oCB = New CCoborrower
>     End If
>     CB = oCB
> End Property

> I now get an error on the "nothing" word reading "Invalid use of object".

> Ideas?

> Craig



> >> I'm having problems referencing a class defined within another.  When I
> try
> >> to get a property from the subclass, I get an error that reads: "Object
> >> variable or With block variable not set (91)" .  What's going on?  Please
> >> see code below.
> >> <snip>

> >> *************code*****************

> >> ***Class CBorrower***
> >> Private oCB As CCoborrower

> >> Public Property Get CB() As CCoborrower
> >>     CB = oCB
> >> End Property

> >> ***Class Coborrower***
> >> Public Property Get FirstName() As Variant
> >>     FirstName = "Craig"
> >> End Property

> >> ***Regular Module***
> >> Sub Main
> >>     dim oB as CBorrower

> >>     set oB = new CBorrower
> >>     debug.print oB.CB.FirstName

> >> End Sub

> >Where do you set oCB?  Anywhere?  Do you have an Initialize function for
> your
> >CoBorrower?

> >--
> >-------------------------
> >| gHaD (Aaron Robinson) |
> >|MJM-PC Solutions, Inc. |
> >|      Chicago, IL      |
> >-------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
Craig,

Quote:
>    If oCB = Nothing Then

Use "If oCB Is Nothing then "  Notice the "Is" instead of the "="

If the code you provided is the same from your project.

Rob

Quote:

>I don't have an initialize function for the CBorrower class.  At the
>suggestion of Robert Rodgers, I modified the "Get CB" property to read

>Public Property Get CB() As CCoborrower
>    If oCB = Nothing Then
>        Set oCB = New CCoborrower
>    End If
>    CB = oCB
>End Property

>I now get an error on the "nothing" word reading "Invalid use of object".



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
I changed the code to:

    If oCB Is Nothing Then
        Set oCB = New CCoborrower
    End If
    CB = oCB

Still errors on the CB=oCB line.  It does run the Set oCB = New CCoborrower
line, though.
"object variable or with block variable not set"

Thoughts?

Craig

Quote:

>I don't have an initialize function for the CBorrower class.  At the
>suggestion of Robert Rodgers, I modified the "Get CB" property to read

>Public Property Get CB() As CCoborrower
>    If oCB = Nothing Then
>        Set oCB = New CCoborrower
>    End If
>    CB = oCB
>End Property

>I now get an error on the "nothing" word reading "Invalid use of object".

>Ideas?

>Craig



>>> I'm having problems referencing a class defined within another.  When I
>try
>>> to get a property from the subclass, I get an error that reads: "Object
>>> variable or With block variable not set (91)" .  What's going on?
Please
>>> see code below.
>>> <snip>

>>> *************code*****************

>>> ***Class CBorrower***
>>> Private oCB As CCoborrower

>>> Public Property Get CB() As CCoborrower
>>>     CB = oCB
>>> End Property

>>> ***Class Coborrower***
>>> Public Property Get FirstName() As Variant
>>>     FirstName = "Craig"
>>> End Property

>>> ***Regular Module***
>>> Sub Main
>>>     dim oB as CBorrower

>>>     set oB = new CBorrower
>>>     debug.print oB.CB.FirstName

>>> End Sub

>>Where do you set oCB?  Anywhere?  Do you have an Initialize function for
>your
>>CoBorrower?

>>--
>>-------------------------
>>| gHaD (Aaron Robinson) |
>>|MJM-PC Solutions, Inc. |
>>|      Chicago, IL      |
>>-------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
Crag,

Remember to always use the Set keyword with objects
    Set CB = oCB

Rob

Quote:

>I changed the code to:

>    If oCB Is Nothing Then
>        Set oCB = New CCoborrower
>    End If
>    CB = oCB

>Still errors on the CB=oCB line.  It does run the Set oCB = New CCoborrower
>line, though.
>"object variable or with block variable not set"

>Thoughts?

>Craig


>>I don't have an initialize function for the CBorrower class.  At the
>>suggestion of Robert Rodgers, I modified the "Get CB" property to read

>>Public Property Get CB() As CCoborrower
>>    If oCB = Nothing Then
>>        Set oCB = New CCoborrower
>>    End If
>>    CB = oCB
>>End Property

>>I now get an error on the "nothing" word reading "Invalid use of object".

>>Ideas?

>>Craig



>>>> I'm having problems referencing a class defined within another.  When I
>>try
>>>> to get a property from the subclass, I get an error that reads: "Object
>>>> variable or With block variable not set (91)" .  What's going on?
>Please
>>>> see code below.
>>>> <snip>

>>>> *************code*****************

>>>> ***Class CBorrower***
>>>> Private oCB As CCoborrower

>>>> Public Property Get CB() As CCoborrower
>>>>     CB = oCB
>>>> End Property

>>>> ***Class Coborrower***
>>>> Public Property Get FirstName() As Variant
>>>>     FirstName = "Craig"
>>>> End Property

>>>> ***Regular Module***
>>>> Sub Main
>>>>     dim oB as CBorrower

>>>>     set oB = new CBorrower
>>>>     debug.print oB.CB.FirstName

>>>> End Sub

>>>Where do you set oCB?  Anywhere?  Do you have an Initialize function for
>>your
>>>CoBorrower?

>>>--
>>>-------------------------
>>>| gHaD (Aaron Robinson) |
>>>|MJM-PC Solutions, Inc. |
>>>|      Chicago, IL      |
>>>-------------------------



Mon, 03 Dec 2001 03:00:00 GMT  
 Classes within Classes
Here's the code that worked:

Public Property Get CB() As CCoborrower
    If oCB Is Nothing Then
        Set oCB = New CCoborrower
    End If
    Set CB = oCB

End Property

The missing bit was the second "Set" command, as the CB property is a Class.
Duh!!

Thanks for the help.

Craig

Craig Buchanan, President
Cogniza, Inc.
Seagate Software Partner
http://www.cogniza.com

+1.612.824.5858

Quote:

>I'm having problems referencing a class defined within another.  When I try
>to get a property from the subclass, I get an error that reads: "Object
>variable or With block variable not set (91)" .  What's going on?  Please
>see code below.

>Thanks in advance,

>Craig Buchanan, President
>Cogniza, Inc.
>Seagate Software Partner
>http://www.cogniza.com

>+1.612.824.5858

>*************code*****************

>***Class CBorrower***
>Private oCB As CCoborrower

>Public Property Get CB() As CCoborrower
>    CB = oCB
>End Property

>***Class Coborrower***
>Public Property Get FirstName() As Variant
>    FirstName = "Craig"
>End Property

>***Regular Module***
>Sub Main
>    dim oB as CBorrower

>    set oB = new CBorrower
>    debug.print oB.CB.FirstName

>End Sub



Mon, 03 Dec 2001 03:00:00 GMT  
 
 [ 20 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Arrays of Classes within Classes

2. memory leaks and classes within classes

3. Not getting Events from classes within classes.

4. VB4.0 16 bit bug: Classes within classes causes "Illegal Function" crash??

5. Class modules 97 - Refering to array within a custom class module

6. Serializing a Class within a Class (Previously Structures)

7. How-To Access Class Members Within The Same Class

8. Raising events from a class within a collection class

9. Dim obj As New Class crt Dim Obj As Class = New Class

10. derive class from protected class in base class

11. Retrieve name of Function, Sub, Class, Property etc from within that item during runtime

12. AddHandler -- Event Associations within an Instance Class.

 

 
Powered by phpBB® Forum Software