PDA

View Full Version : Idea for multi-variable DIM declarations



Robert Hodge
17-06-2013, 04:35
The DIM statement allows for multiple declarations of variables, such as

DIM a, b, c AS LONG

However, in this example, a and b are not of type LONG but are variants. Thus, the AS LONG clause is not applied to the entire list of variable, but only to the last name (c).

This syntax can mislead the reader. It is desirable to have some way to declare all three variables with the same type, without having to respecify the AS clause each time. A few possible syntax options come to mind:

First, instead of a comma, some other punctuation would be used to connect a list of variables:

DIM a & b & c AS LONG

DIM a; b; c AS LONG

Second, the list could be put into parens, or maybe braces:

DIM (a, b, c) AS LONG

DIM {a, b, c} AS LONG

My personal vote, all things being equal, I'd would choose the parenthesized list.

ErosOlmi
17-06-2013, 07:05
DIM a, b, c AS LONG

Declaration produces 3 LONG

Robert Hodge
17-06-2013, 15:56
But I am certain I tried a test with DIM a, b, c AS STRING, and c ended up being a string and a and b were variants.

Am I missing something?

Maybe I am confusing apples and oranges.

If I have a subroutine header like

SUB mySub (a, b, c AS STRING)

then a and b will be variants, correct?

ReneMiner
17-06-2013, 16:20
yes- if you omit type in sub/function the type becomes variant.

but if you



Sub anysub()

Local X, Y as Long ' these are for sure two longs
Local A(), B() as String ' and these are both string arrays - unsized

Double q, r, s ' and these are all local doubles to the sub (short declaration syntax)
Dword C, D Value 12345 ' make two dwords with initial value of 12345
End Sub