ReDim statements can no longer be used to declare array variables

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

inside a procedure , i code


Dim values(1) As Object

.... various other lines of code ...

ReDim values(2) As Object


According to the docs , I should be able to do this ...

However , I receive the compile-time message "ReDim statements can no longer
be used to declare array variables."
 
Right - you have to code:

Dim values() As Object

.... various other lines of code ...

ReDim values(2) As Object

You can't declare it as a 2 element fixed size array and then resize
it as a 3 element array. You have to declare it without fixed size.
(In VB6 you used to be able to declare an array with the ReDim
statement - ugliness heaped on top of ugliness.
 
John A Grandy said:
Dim values(1) As Object

... various other lines of code ...

ReDim values(2) As Object

Simply remove the 'As Object' from the 'ReDim' line. If you don't want to
loose the values stored in the array, use 'ReDim Preserve'.
 
Herfried K. Wagner [MVP]wrote:
]"John A Grandy said:
Dim values(1) As Object

... various other lines of code ...

ReDim values(2) As Object
Simply remove the 'As Object' from the 'ReDim' line. If you don't
want to
loose the values stored in the array, use 'ReDim Preserve'.
 
* (e-mail address removed)-spam.invalid (Jimi) scripsit:
[...]

That will work now.
 

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

Back
Top