initializing a multi-dimensional array

SAnna

New Member
Joined
Mar 7, 2014
Messages
10
What is the correct VBA syntex for the following array (which is from some Matlab code)....

L3_terms =[289.0 5.844 6283.076
35 0 0
17 5.49 12566.15
3 5.2 155.42
1 4.72 3.52
1 5.3 18849.23
1 5.97 242.73];

This doesn't seem to work...
Dim L3_terms()
ReDim L3_terms(7,3)
L3_terms = {{289.0, 5.844, 6283.076}, {35, 0, 0}, {17, 5.49, 12566.15}, {3, 5.2, 155.42}, {1, 4.72, 3.52}, {1, 5.3, 18849.23}, {1 5.97 242.73}}



Also, is there a continuation line that can also be used to help so the code reads better?
 
I just wish VBA had a slick way of initializing an array like Matlab does.
What was wrong with shg's suggestion in Message #6? While you cannot "neaten" it up with line continuations, it is easy enough to do the one time you only need to do it for... columns are separated by commas, rows by semi-colons.
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I could and may do what shg suggested; nothing wrong with that method. It is very tedious though for 15 arrays; some of which are 64x3. And without a continuation line it is very hard to visually see I've got it typed in correctly (I did try it with one of the smaller arrays already).
 
Upvote 0
I could and may do what shg suggested; nothing wrong with that method. It is very tedious though for 15 arrays; some of which are 64x3. And without a continuation line it is very hard to visually see I've got it typed in correctly (I did try it with one of the smaller arrays already).
If it helps any, you can put spaces in to visually separate sections of the data. For example...

Code:
Arr = [{1,2,3;  4,5,6;  7,8,9}]

Plus, if it would help, you could use a comment line above it to number your sections to help identify the first argument's element number...

Code:
[COLOR="#008000"]'       1       2       3[/COLOR]
arr = [{1,2,3;  4,5,6;  7,8,9}]

Not perfect, I know, but something to consider maybe. Also, just so you know, there is a limit of 25 line continuations per individual line of code, so if you had been thinking of breaking up that 64x3 array into 64 line continued groups of 3, that would not work.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,344
Members
448,570
Latest member
rik81h

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top