FUNCTION TO COPY STRING ARRAY !!

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
 
R

RB Smissaert

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
 
R

Ron Rosenfeld

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
 
J

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
 
R

Ron Rosenfeld

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top