# Defining array contents using multiple statements on one line

I'm writing a sub which is going to determine which type of business is being detailed on a particular line of data. It's going to use column positions to check if the data exists, and then output the corresponding string if it does.

I've decided that the best way to organise a group of my arguments is using a 2D array. Now, for readability, clarity and general good coding practice, which is better:

This:

arrAmountColumns(1, 1) = lngInvestmentAmountColumn: arrAmountColumns(1, 2) = "Investment Amount"


or this:

arrAmountColumns(1, 1) = lngInvestmentAmountColumn
arrAmountColumns(1, 2) = "Investment Amount"



I'd go with the second snippet. They're instructions, and instructions read more naturally from top to bottom, rather than from left to right.

Cramming multiple instructions into a single line is a bad habit IMO - it's not because the language supports it that it's necessarily a good idea; the array has 2 columns.. what if it were 10? Would you consider cramming 10 instructions on the same line?

Your indices seem to go (row,column), which amounts to (y,x), which is a bit counter-intuitive, and if you wanted to write that array into a worksheet range, you'd have to transpose it:

Range("A1:B" & UBound(arrAmountColumns,2)) = arrAmountColumns


wouldn't produce the expected result.

By using the first index as your "column" (X) and the second as you "row" (Y), you eliminate that ambiguity and the code would read (x,y), which is a much more intuitive way of visualizing 2D arrays.

• ah, Those values aren't columns per se, this was just a convenient way for storing the position of certain columns in another array, along with their associated descriptors. It felt more intuitive in my head to have: .... | ColumnPositionInArray | Desciption of Column |
– Kaz
Commented Aug 31, 2015 at 18:52
• You can expect an upvote just as soon as we get Reloaded :)
– Kaz
Commented Aug 31, 2015 at 18:55
• (this is why context matters!) In that case, I'd suggest to ditch the array and use a Scripting.Dictionary instead. Commented Aug 31, 2015 at 18:59
• Scripting Dictionaries (along with pivot tables) are next on my list of "Learn how to use these" just as soon as my current project's completed.
– Kaz
Commented Aug 31, 2015 at 19:04
• I've already re-written it once in the last fortnight, my boss might actually start asking when it's going to be finished if I take much longer
– Kaz
Commented Aug 31, 2015 at 19:05