Index | Next 

Multi-dimensional arrays in For Each…Next loops

There is a minor difference in how elements of a multi-dimensional array are accessed when the array appears in a For Each…Next loop:
        Dim arr(10, 20) As Double
        Dim v As Variant
        For Each v In arr
            …
        Next
Under VB6, elements are accessed in column-wise order – that is, first all the elements of first column, then all elements in second column, and so forth. Conversely, under VB.NET the elements are accessed in row-wise fashion – that is, first all the elements of the first row, then all the elements of second row, and so forth. If visiting order is significant, the same loop delivers different results after the migration to VB.NET.
VB Migration Partner emits a warning when a multi-dimensional array appears in a For Each…Next block. If you believe that preserving the original visiting order is important, you can insert a call to the TransposeArray6 method (defined in VBMigrationPartner_Support module), which transposes array elements so that the migrated code works as the original one:
        For Each v In TransposeArray6(arr)
            …
        Next

 

Index | Next