only a variant can hold an array through an assignment - thus
dim strA as Variant
strA = Array("a", "b", "c", "d", "e")
is what works with the limitations you cite.
You could do
dim Dum as Variant
Dim strA(1 to 5)
Dum = Array("a", "b", "c", "d", "e")
i = 1
for j = lbound(dum) to ubound(dum)
strA(i) = j
i = i + 1
Next
Dum = Empty
or you could put your data in a file, read it in, and assign it to elements
of your array.
--
Regards,
Tom Ogilvy
MWE wrote in message
...
Bob: thanks for the reply about using the Array function. I have tried
to use it in the past and it never worked. I now understand that you
can not define the dimenionality of the variable nor can you define its
type. So:
Sub TestArrayFill()
'
' procedure to test the use of the Array function
'
Dim strA(1 to 5) as String
strA = Array("a", "b", "c", "d", "e")
MsgBox strA(1) + " " + strA(5)
End Sub
generates compiler errors as does any other code that defines the scope
of strA or its type.
I can see where the use of Array would be useful, but it bothers me
that it is so vague and it encourages bad code. It also forces the use
of zero as the first index which I find irksome. Logically there is no
such thing as a zeroth index. I understand why it is there -- makes
things more compact -- but it bugs me none the less.
Is there nothing that will allow me to "fill and array" that has been
previously scoped and types. Seems like a very reasonable thing to
want.
Thanks
MWE
---
Message posted from http://www.ExcelForum.com/