Solved

User defined types returned from a class

Posted on 2002-04-03
14
235 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

623 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