Solved

User defined types returned from a class

Posted on 2002-04-03
14
230 Views
Last Modified: 2010-05-02
I have this type in a module:

---------------------------------------------------
Public Type PhoneFlags
    PREF As Boolean
    WORK As Boolean
    HOME As Boolean
End Type

Public Type PhoneNumberType
    PhoneNumberTypes As PhoneFlags
    Number As String
End Type
---------------------------------------------------

and in a Class I have this:

Public Property Get PhoneType() As PhoneFlags
    PhoneType = Phone.PhoneNumberTypes
End Property


But, alas, the compiler tells me that "Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules..."

I thought declaring PhoneFlags as Public in the main module would make in usable by the class, but that is apparently not the case.  Can someone tell me the error of my ways please?
0
Comment
Question by:jbunting
  • 6
  • 3
  • 3
  • +2
14 Comments
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6915771
You need to put it in your class, so that users of your class can see it.

Zaphod.
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 6915825
How about

Friend Property Get PhoneType() As PhoneFlags
   PhoneType = Phone.PhoneNumberTypes
End Property

Friend is seen inside Ur project but not public to others

any how I learned from $EE here to use it to JUMP OVER  VB Limitations of UDT and string arrays passing from a form to module ...

Hope this helps
0
 
LVL 2

Author Comment

by:jbunting
ID: 6915829
If I move the type to the class, then I'm forced to make it private, correct?

I want the main module to be able to use the type as well because I'm returning it from a class property.
0
 
LVL 2

Author Comment

by:jbunting
ID: 6916243
Changing it to Friend does work, but I don't quite understand why.  Since GetPhoneType is a property of the PhoneClass, it seems to me that it should be accessible to any module that has an instance of PhoneClass created in it.

snippets from the msdn library:
Public procedures in a class can be called from anywhere, even by controllers of instances of the class.

Friend makes the procedure visible throughout the project, but not to a controller of an instance of the object.

I thought since I created an instance of PhoneClass in the main module that it would be the "controller of an instance of the object".  At any rate, I thought a public property was always accessible.


0
 
LVL 15

Accepted Solution

by:
ameba earned 100 total points
ID: 6916306
>Changing it to Friend does work, but I don't quite understand why.

Because Friend procedures are not implemented as COM procedures - they do not have to respect all complicated COM rules.

If you want to use PUBLIC property, it is possible to pass UDTs - but UDT must be defined in "Public class module"

>If I move the type to the class, then I'm forced to make it private, correct?

If your project type is Standard EXE, you won't be able to change instancing property of the class - it will be Private.

To have "Public class module", your project type must be ActiveX EXE or DLL.
0
 
LVL 2

Author Comment

by:jbunting
ID: 6916418
I don't have any need to use a Public Property if Friend will work, I'm just trying to understand why it is necessary.

What I don't follow is this though:

The class module is using the UDT definition that is declared in the main (non-class) module.  By virtue of being defined in the main module as public, isn't the UDT therefore a public type? The class module is using the UDT type internally, so it can see it.
0
 
LVL 2

Author Comment

by:jbunting
ID: 6916443
I don't have any need to use a Public Property if Friend will work, I'm just trying to understand why it is necessary.

What I don't follow is this though:

The class module is using the UDT definition that is declared in the main (non-class) module.  By virtue of being defined in the main module as public, isn't the UDT therefore a public type? The class module is using the UDT type internally, so it can see it.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Expert Comment

by:ameba
ID: 6916455
>being defined in the main module as public, isn't the UDT therefore a public type

Not to the outside world (COM).  If you add reference to EXE containing UDT definitions, you'll see in Object Browser only those UDTs defined in public class modules, those in bas modules are not visible.


If you use Friend, VB can do the passing easier and faster - calling Friend procedures is many times faster, see:
http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=158
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 6916795
Sorry I was out

Hope U satisfied by ameba explanation

Viva EE
:-)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6917069
hearing...
0
 
LVL 2

Author Comment

by:jbunting
ID: 6918294
I posted another question for you Bahnass since you did answer my original question first.

(there's still no way to split points is there?  I haven't been on EE very much in awhile)
0
 
LVL 2

Author Comment

by:jbunting
ID: 6918298
and I forgot to say thank you to ameba for clearing things up for me.
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 6918322
'(there's still no way to split points is there?  I haven't been on EE very much in awhile)

Dear U could send Zero point Question to Community support
thus U can Reduce points to the amount U need then send a new Q with the rest of points

Oh I forgot this for next time !!!!
( but now happy to have Ur points :-) )

0
 
LVL 15

Expert Comment

by:ameba
ID: 6918405
Thanks, jbunting
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now