Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a User-Defined Type to a class's method

Status
Not open for further replies.

VBMental

Programmer
Feb 26, 2002
14
0
0
US
I have a class that uses a UDT (user-defined type) defined in a .bas module. I would like to pass a variable of this type to the class's function but every variation of this that I try results in an error message similar to 'Only public user-defined types defined in public object modules can be passed... blah, blah,".

Here's a code example:

Code in module:

Public Type Employee
Name as String
Age as integer
End Type

Code in class (Class1):

Public Sub HireEmployee(Emp as Employee)
...
End Sub

Code in a form:

Public Sub Command1_Click
Dim Emp1 as Employee
Dim EmpClass as new Class1
EmpClass.HireEmployee(Emp1)
End sub

-----------------------------------
Produces the following error:

"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"

 
A tip - I think I saw it posted earlier on this group, is to create an Active X DLL containing the UDT. Compile, add a reference to this - you'll then be able to use it as you need.

I've used this (my thanks to whoever came up with this tip !) and it works fine ..

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top