lmao, but there are a lot more than 3 propertys, there are about 50, and I have more than just that one data type to do.
Thanks, Jebus
Main Topics
Browse All TopicsIn a module I have:
Public Type Corners
C2xOS2 As Integer
C2xOS16 As Integer
C2xIS12 As Integer
End Type
In a class I have:
Private m_PlanCorners As Corners
Public Property Get PlanCorners() As Corners
PlanCorners = m_PlanCorners
End Property
Public Property Let PlanCorners(ByVal v_PlanCorners As Corners)
m_PlanCorners = v_PlanCorners
End Property
I get a compile error saying: Only public user defined types in public object modules can be used as parameters or return types for public procedure of class modules or as fields of public user defined types
Any ideas what going on?
Thanks, Jebus
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Dear dj__jebus,
You don't need to create each property for the object. You can define 50 public variables in an object class. And then you could access the same way as type does.
'Class Module.
Option Explicit
Public C2xOS2 As Integer
Public C2xOS16 As Integer
Public C2xIS12 As Integer
Any further question, please let me know.
Meng
Meng
Dear dj__jebus,
The way I am suggesting you is to create your own new Class Module instead of Type. This new class could be used instead of the public type you defined in the Module.
Actually you do not need to create each property let and get for each variable. Each let and get property procedure was used to protect and filter the incorrect value into each property. But if you have a lot of properties and you do not need to provide each let and get property. You could define each of them as public variable so anyone who use this class can define and set any value into each property or pubic variable.
All you need to do is to make a decision between get way to write the code easier but the value in the variable might not correct. So it 's your point to make a decision.
Any further question, please let me know.
Meng
Normally, you don't want that a property (Get/Set) directly reflects the real data (your real variable). When creating classes and programming a bit object oriented, you hide your variables with the real data ...
A property is sometimes more then passing one variable holding a value (some processing, ...)
But in your case, to convert your user defined types (just holding data one to one), you can best use public variables, so you don't need the property let and get.
Also a quick way to create your classes (with real properties) is to use the Add-In Class Builder.
Regards!
Let and Get properties allow encapsulation of code. For example, you could make a class like this:
public HomePhone as string
Anyother class could read from it and write to it.
You could also make a class like this
private mHomePhone as string
Public Property Let HomePhone( byval RHS as string)
End Property
Public Property Get HomePhone() as string
End Property
Oops, I hit the wrong key, I wasn't finished.
Let and Get properties allow encapsulation of code. For example, you could make a class like this:
public HomePhone as string
Any other class could read from it and write to it.
You could also make a class like this
private mHomePhone as string
Public Property Let HomePhone( byval RHS as string)
' Validation code here
End Property
Public Property Get HomePhone() as string
' Formatting code here
End Property
By using Gets and Lets you can place the validation and formating logic with the data, so that any user of the class has property validated and formatted phone numbers. With the first example, that of just a public variable, there is no validation or formatting so it has to be handled by each user of the class individually. The former is OO, the latter is the usual structured programming chaos.
To have that syntax, you must declare your UDT in "public class module" - you can have public class module in ActiveX project (DLL or EXE), but not in Standard Exe.
So, change project type, add class - make sure it isn't Private, but Public (Instancing = 2, 5 or 6) and move UDT declaration to class.
Another solution which will work for Standard Exe: change "Public" to "Friend" in your methods, e.g.:
Friend Property Get PlanCorners() As Corners
ameba is right with one extra stipulation. You cannot pass a UDT ByVal, it must be ByRef. So in your class you would put:
Private m_PlanCorners As Corners
Friend Property Get PlanCorners() As Corners
PlanCorners = m_PlanCorners
End Property
Friend Property Let PlanCorners(ByRef v_PlanCorners As Corners)
m_PlanCorners = v_PlanCorners
End Property
Idle_Mind
This is my clsCorners, all those declarations:
Public C2xOS2 As Single
Public C2xOS16 As Single
Public C2xIS12 As Single
Then in clsPlan
Public PlanCorners As clsCorners
See now I'm trying to load them from my access db.
Public CN As ADODB.Connection
Public RS As ADODB.Recordset
SQL = "SELECT * FROM PlanCorners WHERE PlanID='" & PlanID & "'"
RS.Open SQL, CN
objPlan.PlanCorners.C10xIS
RS.Close
I get run-time error 3021 "Either BOF or EOF is true, or the record has been deleted. Requested operation requires a current record." Whats the problem with that?
Thanks, Jebus
> I get run-time error 3021 "Either BOF or EOF is true, or the record has been deleted.
> Requested operation requires a current record." Whats the problem with that?
There seems no record where PlanID has the value of your variable PlanID.
Always, when using recordsets, check if the recordset isn't EOF (End Of File), which means we're after the last record. When opening a recordset, and it's immediately EOF, this means there are no records for the SQL-Statement.
So, change your code a bit, like this:
SQL = "SELECT * FROM PlanCorners WHERE PlanID='" & PlanID & "'"
' - Because you just open your recordset to read, open it explicity as ForwardOnly and ReadOnly (much faster!)
RS.Open SQL, CN, adOpenForwardOnly, adLockReadOnly
If RS.EOF Then
' do some errorhandling, or just skip ...
Else
objPlan.PlanCorners.C10xIS
End If
RS.Close
Kind Regards!
Business Accounts
Answer for Membership
by: wsteegmansPosted on 2003-11-29 at 17:20:52ID: 9844073
You can't use User Defined Data Types in a Class. User Defined Data Types only can be used in Modules ...
What to do?
Convert your Corners to a real Class (with three properties). Then it will work!
Regards!