tags:

views:

171

answers:

1

In VB6 it is possible to prepand array identifiers with an empty array index. For example:

Dim x(0 To 20) As Integer
x(0) = 1
Debug.Print x(0)
Debug.Print x()(0)

The debug statements appear to the same thing, even though an empty index is given to the array before the index in the last statement. Does anyone know what this is and why this works?

+4  A: 

Does anyone know what this is and why this works?

It’s a “bug” in the compiler: for reasons of syntactical consistency with the declaration, references to an array x may also be written as x(); thus, it is possible to write the following code:

Dim x() As Integer
x() = SomeFunctionReturningAnArray()

Well, some programmers think this is more consistent than writing x = …. (I thought so, too, for a time.) That you can use it in front of dereferencing the array is simply a hole in the syntax validation, though.

Konrad Rudolph
+1. You can also write `Call SomeSubAcceptingAnArray(x())`
MarkJ