Solved

User defined types returned from a class

Posted on 2002-04-03
14
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 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