Results 1 to 7 of 7

Thread: How possible Redim Preserve Array In Array

  1. #1

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    162

    How possible Redim Preserve Array In Array

    Hi,
    is the simply way redim array in another array?

    My code
    Code:
    Dim arrx(1)
    arrx(0) = Array(0)
    arrx(1) = Array(0)
    how possible redim preserve only array in dimension 1?

    Something like this
    Code:
    Redim Preserve arrx(1)(10)
    ?
    Ten Years After - 01 You Give Me Loving

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How possible Redim Preserve Array In Array

    Something like:

    Code:
        Dim A(1) As Variant
        Dim Temp As Variant
    
        A(0) = Array(0)
        A(1) = Array(0)
    
        Temp = A(1)
        ReDim Preserve Temp(10)
        A(1) = Temp
        Temp = Empty

  3. #3

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    162

    Re: How possible Redim Preserve Array In Array

    Working, but only in 1-d dimension. If 2d
    Code:
    ReDim Preserve Temp(1, 10)
    isn't working...
    Ten Years After - 01 You Give Me Loving

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: How possible Redim Preserve Array In Array

    Can you explain what you need or want to do?

  5. #5

    Thread Starter
    Addicted Member sergeos's Avatar
    Join Date
    Apr 2009
    Location
    Belarus
    Posts
    162

    Re: How possible Redim Preserve Array In Array

    I want gathering data from dynamic list
    Code:
    Level, Name
    3 name1
    4 name2
    1 name3
    3 name4
    1 name5
    2 name6
    2 name7
    4 name8
    ...
    and then show only top 10 by level. And I want iterate four arrays (1 to 4) from first with min values to last array with max values, while 10 records is shows.
    Ten Years After - 01 You Give Me Loving

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: How possible Redim Preserve Array In Array

    Pass the low-level array as an argument and then redim.

    Code:
    
    Option Explicit
    
    Private Sub Form_Load()
        Dim arrx(1)
        arrx(0) = Array(0)
        arrx(1) = Array(0)
    
    
        DoRedim arrx(0), 10
    
        MsgBox UBound(arrx(0))  ' Reports 10, which is correct.
        MsgBox UBound(arrx(1))  ' Reports 0, which is correct.
    
    
    End Sub
    
    Sub DoRedim(TheArray As Variant, NewUpperBound As Long)
        ReDim Preserve TheArray(LBound(TheArray) To NewUpperBound)
    End Sub
    
    
    Enjoy,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How possible Redim Preserve Array In Array

    Another option using UDTs, just because...
    Code:
    Private Type ArrayCont
        A() As Variant ' or long, byte, whatever
        Z() As Variant ' or long, byte, whatever
    End Type
    
    Private Sub Form_Load()
        Dim ac As ArrayCont
        ReDim ac.A(0 to 4)
        ReDim ac.Z(0 to 4)
        ac.A(2) = "Hello World"
        ReDim Preserve ac.A(0 to 9)
        MsgBox ac.A(2)
        Unload Me
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

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



Click Here to Expand Forum to Full Width