variable-sized arrays?

R

Rick Charnes

I don't seem to be able to assign a variable-sized array in a sub:

Dim strCode() As String
strCode(1) = "hello"

tells me "Subscript out of range". What am I doing wrong? Thanks.
 
K

Karl E. Peterson

Rick Charnes said:
I don't seem to be able to assign a variable-sized array in a sub:

Dim strCode() As String
strCode(1) = "hello"

tells me "Subscript out of range". What am I doing wrong? Thanks.

The empty parens in the original Dim only set it up as a dynamic array, which *may*
be resized. You still need to explicitly resize it, as needed, when needed.

Dim strCode() As String
' ...
ReDim strCode(0 To 9) As String
strCode(1) = "hello"
' ...
ReDim Preserve(0 To 19) As String
strCode(11) = "whatever"
' ...

Like that.
 

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