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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Array

Status
Not open for further replies.

MrMeric

Technical User
Apr 1, 2004
48
US
I'm trying to pass an array to an object, but I continually get errors such as: "Can't assign to array"

Here is a snippet of my code:
Code:
Function mytester()
Dim myArray(2) As String
Dim mObj As cSimil
    Set mObj = New cSimil
    
    myArray(0) = "one"
    myArray(1) = "two"
    myArray(2) = "three"
    'Error happens here 
    mObj.CustomerNameArray = myArray()
End Function

Here is the class code:
Code:
Private m_OriginalNameArray() As String

Public Property Let CustomerNameArray(nameArray() As String)
    m_OriginalNameArray = nameArray()
End Property

How do I assign myArray to the m_OriginalNameArray member??

Thanks in advance!
 
Nevermind - Got it!

Code:
Function mytester()
Dim mabj(2) As Variant
Dim myArray() As Variant
Dim mObj As cSimil
Dim i As Integer
    
    Set mObj = New cSimil
    mabj(0) = "one"
    mabj(1) = "two"
    mabj(2) = "three"
    'Pass the name array to the cSimil object
    mObj.SetNameArray = mabj()
    'Set our other local array size
    ReDim myArray(mObj.ArraySize)
    'Get the name array from cSimil
    myArray = mObj.GetNameArray
    'Print the names that are returned!
    For i = LBound(myArray) To UBound(myArray)
        Debug.Print myArray(i)
    Next

End Function

Class code:
Code:
Friend Function GetNameArray() As Variant()
    GetNameArray = m_OriginalNameArray()
End Function
Public Property Let SetNameArray(myArray As Variant)
    m_OriginalNameArray = myArray
    m_ArraySize = SizeOfArray(myArray)
End Property

Thanks to anyone who looked, though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top