type statement & class modules 
Author Message
 type statement & class modules

Just a question to all the experienced VB
programers out there...

I have having a problem using user defined types as
parameters to public functions in class modules,
namely, VB does not seem to allow it.  Here's what
I'm trying to do:

Module: Misc

  Public Type People
      Bob as integer
      george as integer
  end type

Class Module: Use_Function

  Public function getpeople(P as People)

VB 4.0 gives an error when it reachs the public
function above & says that there is an error.  The
properties of the class module are:
 Instancing: 2-Creatable MultiUse
 Name :      Use_Function
 Public :    True

Any way I can do this (passing in a user defined
type into a public class function) without
resorting to something like a global variable?


        Thanks.



Sun, 17 Jan 1999 03:00:00 GMT  
 type statement & class modules

Quote:

> I have having a problem using user defined types as
> parameters to public functions in class modules,
> namely, VB does not seem to allow it...
> Any way I can do this (passing in a user defined
> type into a public class function) without
> resorting to something like a global variable?

You could wrap the user-defined type inside an object then pass the
object into the function.  As far as I know you cannot pass user-defined
variables between modules.

--

Randy Riesenberg

  www:  http://www.netaxs.com/~rriese



Mon, 18 Jan 1999 03:00:00 GMT  
 type statement & class modules


Quote:
>As far as I know you cannot pass user-defined
>variables between modules.

Sure you can. But can a class use a public type declared in another module?


--
Sex isn't the answer. Sex is the question. Yes! is the answer



Mon, 18 Jan 1999 03:00:00 GMT  
 type statement & class modules

Quote:

> Just a question to all the experienced VB
> programers out there...

> I have having a problem using user defined types as
> parameters to public functions in class modules,
> namely, VB does not seem to allow it.  Here's what
> I'm trying to do:

> Module: Misc

>   Public Type People
>       Bob as integer
>       george as integer
>   end type

> Class Module: Use_Function

>   Public function getpeople(P as People)

> VB 4.0 gives an error when it reachs the public
> function above & says that there is an error.  The
> properties of the class module are:
>  Instancing: 2-Creatable MultiUse
>  Name :      Use_Function
>  Public :    True

> Any way I can do this (passing in a user defined
> type into a public class function) without
> resorting to something like a global variable?


>         Thanks.

See Knowledge Base article Q129868: "How to Pass a UDT to an OLE
Automation Server in VB 4.0"
        http://www.microsoft.com/kb/developr/vb/q129868.htm

Although this refers to OLE Automation servers, the same restrictions
apply to user defined types declared outside of the class module.

Another alternative is to create a class module that has nothing but
variables that parallel the elements of the UDT.

Geoff
====================================
      "I brake for MCSD's..."
------------------------------------
The Knowledge Base is YOUR FRIEND!!!
    http://www.microsoft.com/kb/
====================================



Mon, 18 Jan 1999 03:00:00 GMT  
 type statement & class modules

Quote:

> Just a question to all the experienced VB
> programers out there...
> I have having a problem using user defined types as
> parameters to public functions in class modules,
> namely, VB does not seem to allow it.  Here's what
> I'm trying to do:
> Module: Misc
>   Public Type People
>       Bob as integer
>       george as integer
>   end type

This looks to me as if it's a binary relation between two
objects. If your type is really no more complicated than
this then I'd suggest you just use the integers directly
- i.e. it's not really worth making into a VB Type. All it
could do would allow you to pass one parameter instead of
two - phrases involving the words 'deal' and 'big' spring
to mind.

If however your type is more complicated than you're letting
on here, and your reasons for going this way involve the concept
of 'type safe' programming, then ...

Quote:
> Class Module: Use_Function
>   Public function getpeople(P as People)

Obviously you're using VB4. Reading between the lines, you're
either after (with your Public Type) something like a 'collection
of people', in which case you should just use VB's collection object,
with which you'll have no trouble passing as a parameter. Even
if your collection's only ever going to comprise precisely
two 'persons', you could use a VB collection, but it'd hardly be
worth it.

Or your proposed type People is really an object in its own right.
In the latter case, why don't you consider making your People Type
into a fully fledged People Class, with its own type safe properties
and methods?

One additional point - I'm suspicious of the Class you *do* have.
Its name 'Use_Function' seems to suggest that you're using the class
as a bag to hold functions in rather than as a description of an
object and its properties, methods and general behaviour. It seems
to me that what you want is pretty much exactly the opposite of
what you've designed.

Naturally, I apologise wholeheartedly if my poor attempts at second
guessing your intent are completely loopy!

[ >8 ]

Quote:
> Any way I can do this (passing in a user defined
> type into a public class function) without
> resorting to something like a global variable?


{ >8 ]
--
-------------------------------------------------------------------

BB 74 A4 EF 03 F8 44 C1 F3 75 FE C6 7E F9 6E 43         --- at home
-------------------------------------------------------------------


Tue, 19 Jan 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Class Modules & Modules

2. Q(VB5) : Different between module & class module

3. Class Module & Module

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

5. Accessing procedures of a class module from another class module

6. instance of class module can't see own type

7. Accessing Types in a Class Module Problem

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

9. Class Module / User Defined Type

10. User Defined types into a class module

11. Compiler Error Question, attempting to make a class module see a user defined type

12. Error 13 Invalid Type in class module

 

 
Powered by phpBB® Forum Software