Property Array in an Object ? 
Author Message
 Property Array in an Object ?

Hi
Anyone have any ideas how to build a property array in a class ?
A property is simple.  But I'd like the property to look like this...

Object.myproperty(1) = "MyText"
Object.myproperty(9) = "MyText"

Something like this.  How do you set a property to be an array ?

Any suggestions are most appreciated.
Thanx
Steve



Wed, 18 Jun 1902 08:00:00 GMT  
 Property Array in an Object ?
I think you have to do it something like the following.  However, I see no
obvious way of making it automatically support the UBound, LBound, etc.
functions.  I think you will have to write your own functionality for that.
Maybe you could do it if you used Variants.  Dynamic arrays might be a
little harder to implement.

Option Explicit
Private ArrayOfProperties(660 To 670) As String

Public Property Get MyArrayProp(Index As Long) As String
  MyArrayProp = ArrayOfProperties(Index)
End Property

Public Property Let MyArrayProp(Index As Long, _
NewValue As String)
  ArrayOfProperties(Index) = NewValue
End Property

Private Sub Command1_Click()
  'Set property array item 666 to some value
  Me.MyArrayProp(666) = "This is the value of property 666"
  'Retrieve the value of array item 666 from the property
  Debug.Print Me.MyArrayProp(666)
End Sub

--
Howard Henry Schlunder
 Winamp is currently playing:
 Offspring--walla walla wma


Quote:
> Hi
> Anyone have any ideas how to build a property array in a class ?
> A property is simple.  But I'd like the property to look like this...

> Object.myproperty(1) = "MyText"
> Object.myproperty(9) = "MyText"

> Something like this.  How do you set a property to be an array ?

> Any suggestions are most appreciated.
> Thanx
> Steve



Wed, 18 Jun 1902 08:00:00 GMT  
 Property Array in an Object ?
Here is an idea I have used:

This stuff is part of a class....

Private Type udtPromotion
   Prom_ID As Long
   Prom_Name As String
   Prom_Expense As Currency
   Prom_Collection As Currency
   Prom_GST As Currency
   Prom_Member_GST As Currency
   Prom_Member_Count As Long
   Prom_Percentage As Currency
End Type
Private aryP() As udtPromotion

Public Enum colProm
   ipID
   ipName
   ipExpense
   ipCollection
   ipGST
   ipMemberGST
   ipMemberCount
   ipPercentage
End Enum

'---------------------------------------------------------------------------
Public Property Get Prom_Data(ByVal Row As Long, _
                              ByVal Col As colProm) As Variant

If (mvarProm_Count >= Row) Then

   Select Case Col
      Case ipID
         Prom_Data = aryP(Row).Prom_ID
      Case ipName
         Prom_Data = aryP(Row).Prom_Name
      Case ipExpense
         Prom_Data = aryP(Row).Prom_Expense
      Case ipCollection
         Prom_Data = aryP(Row).Prom_Collection
      Case ipGST
         Prom_Data = aryP(Row).Prom_GST
      Case ipMemberGST
         Prom_Data = aryP(Row).Prom_Member_GST
      Case ipMemberCount
         Prom_Data = aryP(Row).Prom_Member_Count
      Case ipPercentage
         Prom_Data = aryP(Row).Prom_Percentage
   End Select

Else

   Err.Raise vbObjectError, "iReconcile-Prom_Data_Get", "Subscript out of
range"

End If

End Property
'--------------------------------------------------------------------
Public Property Let Prom_Data(ByVal Row As Long, _
                              ByVal Col As colProm, _
                              ByVal Value As Variant)

On Error GoTo errhandler

If (mvarProm_Count = -1) Then

   ReDim aryP(Row) As udtPromotion

ElseIf (Row > mvarProm_Count) Then

   ReDim Preserve aryP(0) As udtPromotion

End If

mvarProm_Count = Row

Select Case Col

   Case ipID

      aryP(Row).Prom_ID = Value

   Case ipName

      aryP(Row).Prom_Name = Value

   Case ipExpense

      aryP(Row).Prom_Expense = Value

   Case ipCollection

      aryP(Row).Prom_Collection = Value

   Case ipGST

      aryP(Row).Prom_GST = Value

   Case ipMemberGST

      aryP(Row).Prom_Member_GST = Value

   Case ipMemberCount

      aryP(Row).Prom_Member_Count = Value

   Case ipPercentage

      aryP(Row).Prom_Percentage = Value

End Select

Exit Property
errhandler:

Err.Raise vbObjectError, "iReconcile-Prom_Data_Let", Err.Description

End Property


Quote:
> Hi
> Anyone have any ideas how to build a property array in a class ?
> A property is simple.  But I'd like the property to look like this...

> Object.myproperty(1) = "MyText"
> Object.myproperty(9) = "MyText"

> Something like this.  How do you set a property to be an array ?

> Any suggestions are most appreciated.
> Thanx
> Steve



Wed, 18 Jun 1902 08:00:00 GMT  
 Property Array in an Object ?
Properties fall under the properties collection.
Most properties are read only for objects already appended to a collection.
You need to create the object and set the properties BEFORE you append it to
the collection. ( if you can set that particular property ).
You need to build an array then append it to the property collection.
Then append that property to the object's properties collection.

Don't know if that will help :o

John


Quote:
> Hi
> Anyone have any ideas how to build a property array in a class ?
> A property is simple.  But I'd like the property to look like this...

> Object.myproperty(1) = "MyText"
> Object.myproperty(9) = "MyText"

> Something like this.  How do you set a property to be an array ?

> Any suggestions are most appreciated.
> Thanx
> Steve



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Object Properties, Array Properties

2. Array as a Property of an Object, and Collection

3. Using an array as an object property

4. array object property possible?

5. Objects with arrays as public properties

6. REQ : How to create an activex (VB5) with property like mycontrol.array(x).properties

7. Object array to string array

8. Problem with Property-Object Type-Property

9. Object Properties don't see in properties Window

10. .property vs. object.property question

11. How to store object to an object array?

12. Passing data arrays from object to object

 

 
Powered by phpBB® Forum Software