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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error with a class

Status
Not open for further replies.

ssj3gohan

Programmer
Jun 2, 2003
34
AU
I'm trying to convert a haphazard module to a class to improve reusability. However, I get the following error when I try to compile:

Compile 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


Can anyone help me to understand the meaning of this?

The first instance of code causing the error is:

Code:
 Public Function CDDriveVendorInfo(CDid As Long) As CDVendorInfo

Where CDVendorInfo is a type I've defined in a module within the same project.

Thanks.
 
Try:

Code:
[!]Friend[/!] Function CDDriveVendorInfo(CDid As Long) As CDVendorInfo

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
thanks gmmastros! It worked. But what is a friend function and how does it differ to a public/private function?
 
The underlying issue is that the scoping of the type you've defined is more restrictive than the scoping of the function in which you're trying to use it. Now, there are several levels of scope:

1. Local, such as a variable declared inside a procedure. Can only be seen inside the procedure.
2. Module level, declared as Dim or Private in the General Declarations section of a module. Can only be seen inside the module.
3. Friend level, can only be seen inside a project.
4. Public. Can be seen by other projects that use the class project.

If your type has a more restrictive scope defined than the function that references it, you'll get an error such as the one you have. Using Friend instead of Public is one solution, but another solution is to revisit your type and see if it has been defined as public. If it has, and it's inside a class module, you probably have the Instancing property of the class module set to something other than Public or PublicNotCreatable.

If you're interested in an FAQ that covers the subject of scope in classes, check faq708-5940.

HTH

Bob
 
Thanks,Bob.

I have defined my type as "Public Type CDVendorInfo", which going by your list is less restrictive than the "Friend". So shouldn't that mean that "Public" should work?

You also mentioned instancing. How do I change this property? (When I said class I meant class as in a .cls file in my project)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top