VBA Jagged Array Declaration Error

E

EngPhys_Bate

I am getting the error: "Compile Error: Expected: End of Statement"
when attempting to declare a public (inside the module) 2D jagged
array inside a module. The code, as follows, is declared at the top
of the module:

Dim testStages()() as clsTestStage '2D-array holding tests

Here clsTestStage is a class I have created. I have also tried the
following to see if it was an issue with my custom object:

Dim myString()() as string

and get the same error.

Any ideas as to what could be causing the error? The plan was to go
on and use the ReDim Preserve commands to resize the jagged array
dynamically. I was previously using a dynamic 2D array, but utilizing
a jagged array would be much cleaner and faster in my application.

Any help is greatly appreciated.

Cheers,

bb
 
J

Jonathan West

EngPhys_Bate said:
I am getting the error: "Compile Error: Expected: End of Statement"
when attempting to declare a public (inside the module) 2D jagged
array inside a module. The code, as follows, is declared at the top
of the module:

Dim testStages()() as clsTestStage '2D-array holding tests

Here clsTestStage is a class I have created. I have also tried the
following to see if it was an issue with my custom object:

Dim myString()() as string

and get the same error.

Any ideas as to what could be causing the error? The plan was to go
on and use the ReDim Preserve commands to resize the jagged array
dynamically. I was previously using a dynamic 2D array, but utilizing
a jagged array would be much cleaner and faster in my application.

Any help is greatly appreciated.

You can't declare jagged arrays this way.

Instead, declare the overall variable as a Variant, then use Redim to
declare it dynamically as a 1-D array of variants. Then each individual
variant element of the array can in turn be declared as a 1-D array using
the Redim command, giving you a 2-D jagged array of variants. You can assign
to each element anything which can be assigned to a Variant.
 

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