ReDim Preserve to a Multi-Dimensional Array in Visual Basic 6

前端 未结 10 555
孤城傲影
孤城傲影 2020-11-29 09:44

I\'m using VB6 and I need to do a ReDim Preserve to a Multi-Dimensional Array:

 Dim n, m As Integer
    n = 1
    m = 0
    Dim arrCity() As String
    ReDi         


        
10条回答
  •  一整个雨季
    2020-11-29 09:54

    I know this is a bit old but I think there might be a much simpler solution that requires no additional coding:

    Instead of transposing, redimming and transposing again, and if we talk about a two dimensional array, why not just store the values transposed to begin with. In that case redim preserve actually increases the right (second) dimension from the start. Or in other words, to visualise it, why not store in two rows instead of two columns if only the nr of columns can be increased with redim preserve.

    the indexes would than be 00-01, 01-11, 02-12, 03-13, 04-14, 05-15 ... 0 25-1 25 etcetera instead of 00-01, 10-11, 20-21, 30-31, 40-41 etcetera.

    As long as there is only one dimension that needs to be redimmed-preserved the approach would still work: just put that dimension last.

    As only the second (or last) dimension can be preserved while redimming, one could maybe argue that this is how arrays are supposed to be used to begin with. I have not seen this solution anywhere so maybe I'm overlooking something?

    (Posted earlier on similar question regarding two dimensions, extended answer here for more dimensions)

提交回复
热议问题