Results 1 to 4 of 4

Thread: passing an array as a property

  1. #1

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    you could make the property a variant, they can hold string arrays.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You can create a public property in the form itself.
    VB Code:
    1. Option Explicit
    2. Private m_arrMyProperty As Variant
    3.  
    4. Public Property Get MyProperty() As Variant
    5.     MyProperty = m_arrMyProperty
    6. End Property
    7.  
    8. Public Property Let MyProperty(ByVal p_arrNewValue As Variant)
    9.     m_arrMyProperty = p_arrNewValue
    10. End Property
    11.  
    12. Private Sub Command1_Click()
    13.     Dim arr(1) As String
    14.    
    15.     arr(0) = "AAA"
    16.     arr(1) = "BBB"
    17.    
    18.     MyProperty = arr
    19. End Sub

  3. #3
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Smile Code...

    Alternatively, instead of using nasty variants , just return a dynamic string array...i.e.
    VB Code:
    1. 'Coded by [Digital-X-Treme]...
    2.  
    3. 'In a class, called CStringObj.cls
    4.  
    5. Option Explicit
    6.  
    7. Private m_strAr() As String
    8.  
    9. Private Sub Class_Initialize()
    10.  
    11.     Dim i As Integer
    12.     ReDim m_strAr(10)
    13.    
    14.     For i = 0 To 10
    15.         m_strAr(i) = i
    16.     Next i
    17.  
    18. End Sub
    19.  
    20. Public Property Get My_String_Array() As String()
    21.     My_String_Array = m_strAr()
    22. End Property
    23.  
    24.  
    25. 'In a form...
    26. Option Explicit
    27.  
    28. Private Sub Form_Load()
    29.  
    30.     Dim i As Integer
    31.     Dim x As New CStringObj
    32.     Dim mStrAr() As String
    33.    
    34.     mStrAr() = x.My_String_Array
    35.    
    36.     For i = 0 To UBound(mStrAr())
    37.         Debug.Print mStrAr(i)
    38.     Next i
    39.  
    40. End Sub

    Hope this helps
    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  4. #4
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Smile Info...

    Apologies, that code only included a property Get... Here's the complete code.
    VB Code:
    1. 'Coded by [Digital-X-Treme]...
    2.  
    3. 'In a class, called CStringObj.cls
    4.  
    5. Option Explicit
    6.  
    7. Private m_strAr() As String
    8.  
    9. Private Sub Class_Initialize()
    10.  
    11.     Dim i As Integer
    12.     ReDim m_strAr(10)
    13.    
    14.     For i = 0 To 10
    15.         m_strAr(i) = i
    16.     Next i
    17.  
    18. End Sub
    19.  
    20. Public Property Get MY_String_Array() As String()
    21.     MY_String_Array = m_strAr()
    22. End Property
    23.  
    24. 'As we have to pass ByRef, copy the argument, element by element, into the private array.
    25. Public Property Let MY_String_Array(ByRef strAr() As String)
    26.     Dim i As Integer
    27.  
    28.     ReDim m_strAr(UBound(strAr()))
    29.    
    30.     For i = 0 To UBound(strAr())
    31.         m_strAr(i) = strAr(i)
    32.     Next i
    33.    
    34. End Property
    35.  
    36.  
    37. 'In a form...
    38. Option Explicit
    39.  
    40. Private Sub Form_Load()
    41.  
    42.     Dim i As Integer
    43.     Dim x As New CStringObj
    44.     Dim mStrAr() As String
    45.    
    46.     mStrAr() = x.MY_String_Array
    47.    
    48.     For i = 0 To UBound(mStrAr())
    49.         Debug.Print mStrAr(i)
    50.     Next i
    51.  
    52.     mStrAr(5) = 0
    53.    
    54.     x.MY_String_Array = mStrAr
    55.    
    56.     For i = 0 To UBound(mStrAr())
    57.         Debug.Print mStrAr(i)
    58.     Next i
    59.    
    60. End Sub

    Hope this helps
    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width