• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

User defined types returned from a class

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
jbunting
Asked:
jbunting
  • 6
  • 3
  • 3
  • +2
1 Solution
 
Z_BeeblebroxCommented:
You need to put it in your class, so that users of your class can see it.

Zaphod.
0
 
BahnassCommented:
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
 
jbuntingAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jbuntingAuthor Commented:
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
 
amebaCommented:
>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
 
jbuntingAuthor Commented:
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
 
jbuntingAuthor Commented:
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
 
amebaCommented:
>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
 
BahnassCommented:
Sorry I was out

Hope U satisfied by ameba explanation

Viva EE
:-)
0
 
Richie_SimonettiIT OperationsCommented:
hearing...
0
 
jbuntingAuthor Commented:
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
 
jbuntingAuthor Commented:
and I forgot to say thank you to ameba for clearing things up for me.
0
 
BahnassCommented:
'(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
 
amebaCommented:
Thanks, jbunting
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now