Not able to pass array as an argument to Let Property

kapil

Registered User.
Local time
Today, 19:47
Joined
Oct 4, 2006
Messages
17
Hi,

I want to set the Let and Get property for an array variable. When i am trying to set the value for it, it gives me the error "Can't Assign to Array".. Please help me out to solve this problem. I need to do this using Properties.
Please find the code which i haev written attached with the message

Module function which calls the property
Code:
Public Sub populateScenarioDetails()

Dim objScnroDetails As classScenarioDetails
Set objScnroDetails = New classScenarioDetails
Dim scnroFocus(20) As String
Dim scnroFocusSel(200) As String

For index = 0 To Form_TSD_Input_Form.list_FocusRight.itemsSelected.Count - 1
    scnroFocus(index) = Form_TSD_Input_Form.list_FocusRight.itemsSelected.item(index)
Next index

objScnroDetails.setSelectedFocus = scnroFocus 'sets the Property with the array
scnroFocusSel = objScnroDetails.getSelectedFocus 'retrieves back the array from the property

End Sub

The Class Module containing the Property Functions
Code:
Private arrSelectedFocus(20) As String

Public Property Let setSelectedFocus(selectedFocus() As String)
    arrSelectedFocus = selectedFocus
End Property

Property Get getSelectedFocus() As String()
    getSelectedFocus = arrSelectedFocus
End Property

Please tell me what is the mistake which i am doing which is not letting me use the property functions in case of arrays.. This is working perfectly fine in case of individual variables.

Thanks & Regards,
Kapil
 
You could change your property's data type to variant. A variant type will allow an array assignment. You also typically name your property Let and Get the same.
Code:
Private m_selFocus as variant

Public Property Get SelectedFocus() as variant
  SelectedFocus = m_selFocus
End Property

Public Property Let SelectedFocus(byval vValue as variant)
  If IsArray(vValue) and UBound(vValue) = 19 then
    m_selFocus = vValue
  Else
    MsgBox "invalid array assignment in ..."
  End If
End Property
 
Last edited:

Users who are viewing this thread

Back
Top Bottom