Passing a UDT Variable to a Sub Argument Typed as Variant
Posted on 2004-08-20
I want to develop a generic, reusable Sub procedure to accept any user-defined type (UDT) as a variant argument. I plan to call this Sub procedure from Form modules. I want the Sub procedure to accept any UDT as the variant argument. I envision the Sub procedure to be defined as
Public MySub(ByVal varUDT as Variant)
I'm getting all confused as to (1) where (what kind of module) do I define the UDT? .BAS module? Class module? Can I define a single variable as a UDT type and have this variable be used anywhere in an application? If so, where do I place the statement
Public pubVar as MyUDT
where pubVar is the name of the variable and MyUDT is defined by a Type statement somewhere.
I'm getting all twisted up with what kind of modules to place various statements so that I can have a Public Sub Procedure and public variables of UDT type.
The above text is a simplified version of my problem. In actuality, I'm trying to write a generic procedure to add, change, delete and insert fixed-length records into any binary file (specified by an argument). In my struggles with this problem I've gotten the following error message several times:
Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types.
I need a more elementary explanation than this authentic Visual Basic gibberish.