Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Property Let/Get and User Defined Types

Status
Not open for further replies.

rayner1

Programmer
Jul 12, 2001
3
GB
Hi, I just joined in the hope that somebody here could help me.

I have a user defined type called typCurrency defined (in a module) as:


Public Type typCurrency
Code As String
Description As String
Index As Integer
End Type


In a separate class I have the following code:


Private mtypCurrencyList(1000) As Variant

Friend Property Get CurrencyList(intNumber As Integer) As typCurrency
CurrencyList = mtypCurrencyList(intNumber)
End Property

Friend Property Let CurrencyList(intNumber As Integer, typList As typCurrency)
mtypCurrencyList(intNumber) = typList
End Property


Now...the problem.

When I try to assign a value to CurrencyList as follows:

CurrencyList(1).Index = 1

The code goes into the Property Get, when it should go into the Let. Why? What have I done wrong? How do I write a Property that makes use of a user defined type?

Thanks in advance,

Rayner1
 
Oops, slight error in there:

Private mtypCurrencyList(1000) As Variant

should say:

Private mtypCurrencyList(1000) As typCurrency
 
No, it is correct - it uses the Property Get to get the 1st element of the mtypCurrencyList array and sets the index value to 1.

Think of it this way (this may not make it any clearer ...)

Code:
Dim x as typCurrency
x = CurrencyList(1)  ' Uses Property Get
x.Index = 1          ' Directly setting the value in the type

Chaz
 
Okay, removed the array parts to give the following:

Private mtypCurrencyList As typCurrency

Friend Property Get CurrencyList() As typCurrency
CurrencyList = mtypCurrencyList
End Property

Friend Property Let CurrencyList(typList As typCurrency)
mtypCurrencyList = typList
End Property


Still goes into Get instead of Let. Have I completely missed the point (not unusual :) )
 
OK, the following will use Let:

Dim x as typList
CurrencyList = x

The following will use Get:
CurrencyList.Index = 1

Perhaps it would be better if you were to say what you are trying to achieve.

Chaz


 
Your Let statement is expecting a data type of typCurrency and you are trying to assign a different data type.


You might have to create 3 Let/Get statements, 1 for Code, 1 for Description and 1 for Index...

Private mtypCurrencyList(1000) As Variant

Friend Property Get Index(intNumber As Integer) As long
Index = mtypCurrencyList(intNumber).Index
End Property

Friend Property Let CurrencyList(intNumber As Integer, lngIndex As Long)
mtypCurrencyList(intNumber).Index = lngIndex
End Property

the same for the other 2 variables in your UDT...
.
.
 
Sorry last property should be

Friend Property Let Index(intNumber As Integer, lngIndex As Long)
mtypCurrencyList(intNumber).Index = lngIndex
End Property
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top