Troubles with arrays

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having difficulties with using string arrays, I use the following code
to define & fill a string array, but I keep getting a type mismatch error.

Dim a() As String
a = Array("Funny", "Dead")

Amiag1200
 
I have done this but the problem is that I have to convert them to Strings
before I can use them in some functions, I thought that there is a declare as
strings to avoid this problem.

Amiga 1200
 
You can't assign to an array in VBA - and in any case Array() doesn't
return an array as such, it returns a Variant containing an array. If
you need an Array of String, there's no alternative to assigning values
to each element individually.
 
John Nurick wrote in message
You can't assign to an array in VBA - and in any case Array() doesn't
return an array as such, it returns a Variant containing an array. If
you need an Array of String, there's no alternative to assigning values
to each element individually.

Dim a() As String
a = Split("Funny|Dead", "|")
 
Dim a() As String
a = Split("Funny|Dead", "|")

Thanks for that. It looks as if VBA lets one assign to dynamic arrays
but not to static ones, and the source of the OP's problem is that
Array() returns a Variant containing an array, not an actual array.
Which means that even though this

Dim a() As String
a = Array("Hello","World")

doesn't work, this

Dim a() As String
a = Split(Join(Array("Hello", "World"), "|"), "|")

does, because Split() returns a real array.
 
Back
Top