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

前端 未结 10 586
孤城傲影
孤城傲影 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 10:06

    Easiest way to do this in VBA is to create a function that takes in an array, your new amount of rows, and new amount of columns.

    Run the below function to copy in all of the old data back to the array after it has been resized.

     function dynamic_preserve(array1, num_rows, num_cols)
    
            dim array2 as variant
    
            array2 = array1
    
            reDim array1(1 to num_rows, 1 to num_cols)
    
            for i = lbound(array2, 1) to ubound(array2, 2)
    
                   for j = lbound(array2,2) to ubound(array2,2)
    
                          array1(i,j) = array2(i,j)
    
                   next j
    
            next i
    
            dynamic_preserve = array1
    
    end function
    

提交回复
热议问题