User defined types as returnvalue of a function 
Author Message
 User defined types as returnvalue of a function

Hi,

I'm trying to use a function I wrote in a class module. THe function
returns an array of records. I keep getting the same error, it is:

Only public user defined types defined in public object modules can be
used as parameters or return types for public procedures for class
modules or as fields of public user defined types.

I think I have to define the type in a public object module, how do I
achieve that?
--
Marco

===========
Reply to my email please.

If you're interested in recipes check out my site: http://www.*-*-*.com/ ~schel

Please remove no_spam_ from my address



Mon, 04 Jun 2001 03:00:00 GMT  
 User defined types as returnvalue of a function
You can:

1- Set your User-defined Type As Public:

  Public Type MyStructure
   A As Byte
   B As Byte
  End Type
  Public MyVariable As MyStructure
'Note that your Class Module must also be defined as Public.
'Passing a structure as Return Value is not that way it should be.
'If you dis-assemble this function, you'll see a lot of wasting-time
'operations.

2- Pass the structure as a ByRef argument which the called function will
   alterate:

  Public Type MyStructure
   A As Byte
   B As Byte
   C As Byte
  End Type
  Public MyVariable As MyStructure

 Public Function AddAndStoreOnC (ByRef Struct As MyStructure)
   'No return value! An eventual return value could have another
   'meaning like telling if the function worked properly, etc.

   Struct.C = Struct.A + Struct.B
 End Function

 Private Sub MySub()
   Dim MickeyMouse As MyStructure
   MickeyMouse.A = 2
   MickeyMouse.B = 5
   AddAndStoreOnC MickeyMouse

   'Now, MickeyMouse.C has the value 7.
 End Sub

                        Martin

Quote:

> Hi,

> I'm trying to use a function I wrote in a class module. THe function
> returns an array of records. I keep getting the same error, it is:

> Only public user defined types defined in public object modules can be
> used as parameters or return types for public procedures for class
> modules or as fields of public user defined types.

> I think I have to define the type in a public object module, how do I
> achieve that?
> --
> Marco

> ===========
> Reply to my email please.

> If you're interested in recipes check out my site: http://www.bart.nl/~schel

> Please remove no_spam_ from my address



Mon, 04 Jun 2001 03:00:00 GMT  
 User defined types as returnvalue of a function


(Marco Schellings) schreibt:

Quote:
>I think I have to define the type in a public object module, how do I
>achieve that?

I don't know about VB6 details, but a "public" object module in  this context
might be either a BAS module, or a public CLS module. Unfortunately the
"public" property is not shown by VB5 in the Properties of a module, for
classes the ClassWizard add-in allows to access and define these properties.
Otherwise you'll have to inspect/edit the disk images of the modules.

DoDi



Wed, 06 Jun 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. User defined types as returnvalue of a function

2. User Control - User-defined type not defined

3. Return NULL from a user-defined type function

4. Use user defined type in place of array for function returns

5. User Defined Type and Property Functions

6. user defined type in function

7. User defined types, arrays and functions: ARGH!

8. Public user-defined types as sub function arguments (VB5)

9. Passing a user defined type to a function.

10. Passing User-defined types to public functions?

11. Help with passing user defined types as variables in functions - VB4 32bit

12. Returning user defined types from functions

 

 
Powered by phpBB® Forum Software