|
-
Aug 14th, 2001, 01:33 PM
#1
Thread Starter
New Member
Help With Property Array
Hey guys,
I'm fairly new to properties and having some problems with a property array. I think I have the Property Get and Let procedures correct, but I can't seem to get the ReadProperties and WriteProperties functions. Here is the code that I have. Can anyone help with this?
Code:
Public m_Test() As String
Public Property Get Test() as String()
Test = m_Test
End Property
Public Property Let Test(ByRef New_Test() As String)
Dim I as Integer
Redim m_Test(Ubound(New_Test,1))
For I = LBound(New_Test,1) To UBound(New_Test,1)
Test(I) = New_Test(I)
Next I
End Property
-
Aug 14th, 2001, 09:05 PM
#2
Hyperactive Member
Hi, here is a code snippet that I use before for a ActiveX UserControl ListBox. It uses an array, persist it so that it can be added to the Listbox at Run-Time and Design-Time.
Read the codes on how to InitProp, ReadProp, WriteProp on Property Arrays. I hope it helps.
////////////////////////////////////////////////////////////////////////////
Option Explicit
Private m_strExtenderName As String
Private m_vListArray() As Variant
Private m_intArrayElements As Integer
Public Event OnClick()
Public Property Get ListArray(pIndex As Integer) As String
ListArray = m_vListArray(pIndex)
End Property
Public Property Let ListArray(pIndex As Integer, pValue As String)
m_vListArray(pIndex) = pValue
List1.AddItem pValue
End Property
Private Sub UserControl_InitProperties()
'///////// Assign and Initialize Values to Variables /////////
m_intArrayElements = 3
m_strExtenderName = Extender.Name
'Initialize the Array with a Redim and Allocate Elements
'It assumes Option Base 0
'so Redim xxx(3) means there are 4 Elements
'If Option Base 1
'then Redim xxx(3) means there are 3 Elements
ReDim m_vListArray(m_intArrayElements)
Dim i As Integer
'////////////////////////////////////////////////////////////
'Allocate the Extender Name to the Elements of the Array
'and Add that to the ListBox
For i = 0 To m_intArrayElements 'OR UBound(m_vListArray)
ListArray(i) = m_strExtenderName & " Item " & i
Next i
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
'Retrieve the Total number of Elements
m_intArrayElements = PropBag.ReadProperty("ArrayElements", 0)
'Redim the Array
ReDim m_vListArray(m_intArrayElements)
'Retrieve the contents of each element
Dim i As Integer
For i = 0 To UBound(m_vListArray) 'OR m_intArrayElements
ListArray(i) = _
PropBag.ReadProperty("ListArray" & i, 0)
Next
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
'Store the Total Array Elements
Call PropBag.WriteProperty("ArrayElements", UBound(m_vListArray), 0)
'Store the contents of each element
Dim i As Integer
For i = 0 To UBound(m_vListArray)
Call PropBag.WriteProperty _
("ListArray" & i, ListArray(i), 0)
Next
End Sub
William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.net
*** Things are always the darkest before they go pitch black ***
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|