Is there a way to set an array = to another array without looping through elements?
In the following code (slightly modified from a post by Skip), I'm passing an array to a function, changing it then returning the changed array.
I'd like to clean up the return some if possible. Hoping for something like sArray() = test(sArray). Thanks for any help.
Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.
In the following code (slightly modified from a post by Skip), I'm passing an array to a function, changing it then returning the changed array.
I'd like to clean up the return some if possible. Hoping for something like sArray() = test(sArray). Thanks for any help.
Code:
Sub demo()
Dim sArray(2) As String
Dim ReturnArray As Variant
sArray(0) = "aa"
sArray(1) = "bb"
sArray(2) = "cc"
ReturnArray = test(sArray)
For i = LBound(ReturnArray, 1) To UBound(ReturnArray, 1)
sArray(i) = ReturnArray(i)
MsgBox sArray(i)
Next
End Sub
Function test(ByRef strArray As Variant) As Variant
Dim i As Integer
For i = LBound(strArray, 1) To UBound(strArray, 1)
strArray(i) = strArray(i) & " please work"
Next
test = strArray
End Function
![[thumbsup2] [thumbsup2] [thumbsup2]](/data/assets/smilies/thumbsup2.gif)
I think I've forgotten this before.