Passing Classes to other classes (using user defined types) 
Author Message
 Passing Classes to other classes (using user defined types)

All:

I'm a newbie to VB and would like to know (I think?) how to send a class as
a parameter to another class.  Basically, VB gives me an error:
 "Object Doesn't Support this Property or Method"
when clearly, the method is there.

In english, I would like to have a class which represents the columns in a
particular DB table.  This class would be used by the recordset object we
would create to encapsulate the table.  It could also be used by any other
modules that want to represent rows in this table.  What I want to be able
to do is communicate with the recordset class by passing this 'table class'
to and from it.  But, the recordset class we created does not like getting
another class as a parameter to one of its methods, thus the above error.

Thanks in advance...

In more detail (though I've left out a lot):

1. I created class to represent the columns in a particular table.The
class contains a user defined type, ie:
 Private Type MyTableRecType
     column1 As String * 10
     column2 As String * 20
 End Type
and has methods to read and write to each column, so to speak.
Thus, I can:
 dim X as MyTableRec
and use:
 x.column1 = "hello"
 x.column2 = "goodbye"
this works great!

2. I created another class which is basically an object encapsulating
an ADO record set, exposing most of its methods, with good error handling,
etc.  In this class, I'm using the 'table class' created above to store a
local copy of the 'current row' values as they are being retreived (ie: via
the MoveFirst methods etc).  This works great, as well.

3. What I would like to do is to have my 'main' program use both classes
above and pass the class instance as a way of transfering row. In other
words:

Sub main()
    Dim local_instance_of_record As New TestTableRecordType
    Dim local_record_set as New TestTableRecordSet
    Set local_record_set as New TestTableRecordSet

    local_record_set.get_first_row  'assume this moves to 1st row

    'the error appears on the line below, where VB says that the
    'object doesn't support the property

    local_record_set.read_entire_row ( local_instance_of_record)

end sub

The local_record_set.read_entire_row looks as follows:

Public Sub read_entire_row(Vdata As TestTableRecordType)
    Vdata.column1 = MyTableRow.column1
    Vdata.column2 = MyTableRow.column2
End Sub

(Note that the MyTableRow is a local copy of the same class,
TestTableRecordType in the recorrdset class).

I hope I made myself clear.... Can't understand the problem...

Lou Solomon



Fri, 31 May 2002 03:00:00 GMT  
 Passing Classes to other classes (using user defined types)

Quote:

> All:

> I'm a newbie to VB and would like to know (I think?) how to send a class as
> a parameter to another class.  Basically, VB gives me an error:
>  "Object Doesn't Support this Property or Method"
> when clearly, the method is there.

There's a bug in VB where passing a class in a .DLL to a class in another
.DLL sometimes results in a "438" OLE automation error. The workaround is
to declare the parameters as properties, and set them before calling a
method without any parameters. A PITA. Supposedly fixed, too.

--

Fred Morris

address



Fri, 31 May 2002 03:00:00 GMT  
 Passing Classes to other classes (using user defined types)
Fred (And Others):

Thanks for you help, but (with someone elses help), I found the answer.

Basically, for what its worth, the fix was not to have the 'parameter' in
parenthesis:

This didn't work:
                            object2.method( object1)

This did work:
                            object2.method object1

Since I didn't make any change in the actual param list in object2.method,
I've no idea why
the above two things work differently.  Probably something to do with a "by
value" or "by reference" or whatever...

25 years of programming.... darn, its not fun to be a newbie again.  And to
be honest, the printed documentation regarding these things is not really
all that good (I know it's complex).  As to the on-line documentation...
ouch!!! I made the mistake of installing the Visual Studio version...
Everytime I wind up looking up someting via the index, I have to go through
way to many false leads (ie: references to C++, VBA, etc), before finding
(if I do) the information I need.

But thanks again for the help.

Lou Solomon


Quote:


> > All:

> > I'm a newbie to VB and would like to know (I think?) how to send a class
as
> > a parameter to another class.  Basically, VB gives me an error:
> >  "Object Doesn't Support this Property or Method"
> > when clearly, the method is there.

> There's a bug in VB where passing a class in a .DLL to a class in another
> .DLL sometimes results in a "438" OLE automation error. The workaround is
> to declare the parameters as properties, and set them before calling a
> method without any parameters. A PITA. Supposedly fixed, too.

> --

> Fred Morris

> address



Fri, 31 May 2002 03:00:00 GMT  
 Passing Classes to other classes (using user defined types)
Just to let you know why using parenthesis did not work is becuase when you
use them it implies you are calling a function and expecting a result.
Since you did not have something like:

    x=object2.method(object1)

it failed because it did not have a place to put the result.

If for some reason you did want to use the parenthesis and not care about
the result you could call it like:

    call object2.method(object1)

Just letting you know the reason.

-Clint LaFever

http://www.saic.com
http://lafever.iscool.net (personal)

Quote:

>Fred (And Others):

>Thanks for you help, but (with someone elses help), I found the answer.

>Basically, for what its worth, the fix was not to have the 'parameter' in
>parenthesis:

>This didn't work:
>                            object2.method( object1)

>This did work:
>                            object2.method object1

>Since I didn't make any change in the actual param list in object2.method,
>I've no idea why
>the above two things work differently.  Probably something to do with a "by
>value" or "by reference" or whatever...

>25 years of programming.... darn, its not fun to be a newbie again.  And to
>be honest, the printed documentation regarding these things is not really
>all that good (I know it's complex).  As to the on-line documentation...
>ouch!!! I made the mistake of installing the Visual Studio version...
>Everytime I wind up looking up someting via the index, I have to go through
>way to many false leads (ie: references to C++, VBA, etc), before finding
>(if I do) the information I need.

>But thanks again for the help.

>Lou Solomon





>> > All:

>> > I'm a newbie to VB and would like to know (I think?) how to send a
class
>as
>> > a parameter to another class.  Basically, VB gives me an error:
>> >  "Object Doesn't Support this Property or Method"
>> > when clearly, the method is there.

>> There's a bug in VB where passing a class in a .DLL to a class in another
>> .DLL sometimes results in a "438" OLE automation error. The workaround is
>> to declare the parameters as properties, and set them before calling a
>> method without any parameters. A PITA. Supposedly fixed, too.

>> --

>> Fred Morris

>> address



Fri, 31 May 2002 03:00:00 GMT  
 Passing Classes to other classes (using user defined types)
Clint:

I truly do appreciate the explanation!  My backround is in DEC-BASIC (a very
structured form of our favorite language, but no OOP kind of stuff), and so
much of this is new to me.

Like the proverbial eskimo/thousand_words_for_snow analogy, VB seems to have
lots of ways to do things,
and honestly, a lot of them aren't needed.

Many of the languages I've known (always) use parenthesis to indicate the
parameters passed to a function/object/subprogram/whatever, without any
confusion as to whether the func/obj returns a value
or not (ie; as they say in programming circles, this can be indicated
whether there is an lvalue or not).

Oh, well.  Seriously, thanks.

Lou


Quote:
> Just to let you know why using parenthesis did not work is becuase when
you
> use them it implies you are calling a function and expecting a result.
> Since you did not have something like:

>     x=object2.method(object1)

> it failed because it did not have a place to put the result.

> If for some reason you did want to use the parenthesis and not care about
> the result you could call it like:

>     call object2.method(object1)

> Just letting you know the reason.

> -Clint LaFever

> http://www.saic.com
> http://lafever.iscool.net (personal)


> >Fred (And Others):

> >Thanks for you help, but (with someone elses help), I found the answer.

> >Basically, for what its worth, the fix was not to have the 'parameter' in
> >parenthesis:

> >This didn't work:
> >                            object2.method( object1)

> >This did work:
> >                            object2.method object1

> >Since I didn't make any change in the actual param list in
object2.method,
> >I've no idea why
> >the above two things work differently.  Probably something to do with a
"by
> >value" or "by reference" or whatever...

> >25 years of programming.... darn, its not fun to be a newbie again.  And
to
> >be honest, the printed documentation regarding these things is not really
> >all that good (I know it's complex).  As to the on-line documentation...
> >ouch!!! I made the mistake of installing the Visual Studio version...
> >Everytime I wind up looking up someting via the index, I have to go
through
> >way to many false leads (ie: references to C++, VBA, etc), before finding
> >(if I do) the information I need.

> >But thanks again for the help.

> >Lou Solomon





> >> > All:

> >> > I'm a newbie to VB and would like to know (I think?) how to send a
> class
> >as
> >> > a parameter to another class.  Basically, VB gives me an error:
> >> >  "Object Doesn't Support this Property or Method"
> >> > when clearly, the method is there.

> >> There's a bug in VB where passing a class in a .DLL to a class in
another
> >> .DLL sometimes results in a "438" OLE automation error. The workaround
is
> >> to declare the parameters as properties, and set them before calling a
> >> method without any parameters. A PITA. Supposedly fixed, too.

> >> --

> >> Fred Morris

this
> >> address



Sat, 01 Jun 2002 03:00:00 GMT  
 Passing Classes to other classes (using user defined types)
Actually I don't think that's quite right. Sometimes using parentheses or
getting rid of them will hide the "438" bug.

While

   foo( oParam )

is a function call,

   foo (oParam)

evaluates the argument before passing it to the routine...

At least that's what I think is going on. Frankly, I'm not certain. But
I've noticed that myself, and even noticed the compiler "helpfully"
putting parentheses on some things.. usually because I found I didn't want
its help.

(19 years, not quite as many Lou ;-) (What I can say is, after 19 years,
if it ain't documented I don't want to know; I shouldn't have to know. I
shouldn't even know.)

Quote:

> Just to let you know why using parenthesis did not work is becuase when you
> use them it implies you are calling a function and expecting a result.
> Since you did not have something like:

>     x=object2.method(object1)

> it failed because it did not have a place to put the result.

> If for some reason you did want to use the parenthesis and not care about
> the result you could call it like:

>     call object2.method(object1)

> Just letting you know the reason.

> -Clint LaFever

> http://www.saic.com
> http://lafever.iscool.net (personal)


> >Fred (And Others):

> >Thanks for you help, but (with someone elses help), I found the answer.

> >Basically, for what its worth, the fix was not to have the 'parameter' in
> >parenthesis:

> >This didn't work:
> >                            object2.method( object1)

> >This did work:
> >                            object2.method object1



Sat, 01 Jun 2002 03:00:00 GMT  
 Passing Classes to other classes (using user defined types)

Quote:

> Clint:

> I truly do appreciate the explanation!  My backround is in DEC-BASIC (a very
> structured form of our favorite language, but no OOP kind of stuff), and so
> much of this is new to me.

The Access Report Wizard does bear a certain resemblance to RJP's
venerable XENTIS/FIS, doesn't it?  ;-) ;-) ;-)


Sat, 01 Jun 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Passing an array of user-defined data type to a class module

2. Passing User Define Types to Classes

3. Passing used-defined data types to a class

4. Error using user-defined type in parameter of public procedure in a class module

5. Using public user defined types in a class

6. Using user defined types or arrays in classes

7. Using a Class to create user-defined types in VBScript

8. Using user defined types or arrays in classes

9. Classes, Collections, and User Defined Types

10. Class and User Defined Types

11. Class Module / User Defined Type

12. User Defined types into a class module

 

 
Powered by phpBB® Forum Software