FUNCTION TO COPY STRING ARRAY !!

  • Thread starter Thread starter jay dean
  • Start date Start date
J

jay dean

Hi -

I am looking for a vba function, copyArray()of type String, that will
take in one String array, and produce a copy of the input.

Specs:
(1)The function should be able to take in either 1D or 2D string array,
and produce its copy.
(2)If the input is just "" or vbNullString, the output should be the
same as well.

Any help will be appreciated!
Thanks
Jay Dean
 
Sub test()

Dim i As Long
Dim arrString1(0 To 10) As String
Dim arrString2() As String

For i = 0 To 10
arrString1(i) = Chr(i + 65)
Next i

'copy the array
arrString2 = arrString1

For i = 0 To 10
MsgBox arrString2(i)
Next i

End Sub


RBS
 
Hi -

I am looking for a vba function, copyArray()of type String, that will
take in one String array, and produce a copy of the input.

Specs:
(1)The function should be able to take in either 1D or 2D string array,
and produce its copy.
(2)If the input is just "" or vbNullString, the output should be the
same as well.

Any help will be appreciated!
Thanks
Jay Dean

If your function argument is a variant, and it's output is a variant, you can
just set the input equal to the output.

e.g.:

==========================
Function CopyStringArray(s1)
CopyStringArray = s1
End Function
=========================

If you need to, you can cycle through each element of the array to ensure it is
of type String. You can also test to see if it is an array.
--ron
 
Thanks, Ron! I think using the variant datatype even though uses more
memory would suffice for this purpose. I am trying to keep loops to a
minimum so your approach works well.

Jay Dean
 
Thanks, Ron! I think using the variant datatype even though uses more
memory would suffice for this purpose. I am trying to keep loops to a
minimum so your approach works well.

Jay Dean


Glad to help. Thanks for the feedback.
--ron
 
Back
Top