Creating a String() from a list of items... ??

M

Martin Schmid

Dim types() As String
types = Array("RFH-2", "FFH-2")

I'm getting an error... i.e., I need an array of strings, but the Array
function returns variants...

How do I create a string array from a list of items?
 
J

Jonathan West

Martin Schmid said:
Dim types() As String
types = Array("RFH-2", "FFH-2")

I'm getting an error... i.e., I need an array of strings, but the Array
function returns variants...

How do I create a string array from a list of items?

What the Array function returns is a single Variant that contains an array
of Variants. therefore this will work.

Dim types as Variant
types = Array("RFH-2", "FFH-2")

If you must have the final result as an array of strings, then you need to
do the conversion yourself, like this

Dim vTypes as Variant
Dim strTypes() as String
Dim i As Long
vTypes = Array("RFH-2", "FFH-2")
ReDim strTypes(Ubound(vTypes))
For i = 0 to Ubound(vTypes)
strTypes(i) = vTypes(i)
Next i

But I suspect that you will be OK with a Variant containing the array.
 

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