+ Reply to Thread
Results 1 to 2 of 2

redim preserve multidimensional array

Hybrid View

welchs101 redim preserve... 12-07-2011, 02:10 PM
welchs101 Re: redim preserve... 12-07-2011, 02:48 PM
  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    redim preserve multidimensional array

    I have two arrays........if an element is in both then dont transfer it to the "unique" array however, if it is in one and not the other then transfer it to the unique array. But for some reason the unique array is not increasing in size..........



    ReDim unique_file_array(3, UBound(stdy_file_array1))
    unique_file_array = stdy_file_array1
    
    
    'For x = 1 To UBound(unique_file_array, 2)
    'MsgBox (unique_file_array(1, x))
    'MsgBox (unique_file_array(2, x))
    'MsgBox (unique_file_array(3, x))
    'Next x
    
    MsgBox ("ubound unique is   " & UBound(unique_file_array, 2))
    
    For x = 1 To UBound(stdy_file_array2, 2)
    match_found = False
        For y = 1 To UBound(unique_file_array, 2)
            If stdy_file_array2(1, x) = unique_file_array(1, y) Then
                match_found = True
                Exit For
            End If
        Next y
        
        If Not match_found Then
        MsgBox ("in not match found")
            ReDim Preserve unique_file_array(3, (UBound(unique_file_array) + 1))
            unique_file_array(1, UBound(unique_file_array) + 1) = stdy_file_array2(1, x)
            unique_file_array(2, UBound(unique_file_array) + 1) = stdy_file_array2(2, x)
            unique_file_array(3, UBound(unique_file_array) + 1) = stdy_file_array2(3, x)
        End If
        
    
    Next x

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: redim preserve multidimensional array....i am doing it wrong

    i found error.......when calculating ubound.......i used "Ubound(unique_file_array)" but it should have been "Ubound(unique_file_array,2)" to account for 2nd dimension.

    see code below
    ReDim unique_file_array(3, UBound(stdy_file_array1))
    unique_file_array = stdy_file_array1
    
    
    'For x = 1 To UBound(unique_file_array, 2)
    'MsgBox (unique_file_array(1, x))
    'MsgBox (unique_file_array(2, x))
    'MsgBox (unique_file_array(3, x))
    'Next x
    
    MsgBox ("ubound unique is   " & UBound(unique_file_array, 2))
    
    For x = 1 To UBound(stdy_file_array2, 2)
    match_found = False
        For y = 1 To UBound(unique_file_array, 2)
            If stdy_file_array2(1, x) = unique_file_array(1, y) Then
                match_found = True
                Exit For
            End If
        Next y
        
        If Not match_found Then
        MsgBox ("in not match found")
            'ReDim Preserve unique_file_array(3, UBound(unique_file_array, 2))
            ReDim Preserve unique_file_array(3, (UBound(unique_file_array, 2) + 1))
            MsgBox ("ubound unique is   " & UBound(unique_file_array, 2))
            
            unique_file_array(1, UBound(unique_file_array, 2)) = stdy_file_array2(1, x)
            unique_file_array(2, UBound(unique_file_array, 2)) = stdy_file_array2(2, x)
            unique_file_array(3, UBound(unique_file_array, 2)) = stdy_file_array2(3, x)
        End If
        
    
    Next x

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1