Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Redim Preserve Multi Dimensional Array

Thread Tools Display Modes
Old 06-03-2003, 04:19 PM
Jacque Jacque is offline
Join Date: Aug 2002
Location: Redondo Beach, CA
Posts: 136
Default Redim Preserve Multi Dimensional Array

I have an array myArray(2,6). I need to add data to this array at a later time but I need it to be myArray(5,10). Is there a way to do this?

I've read you can only resize the last array dimension and you can't change the number of dimensions at all.

I have seen somewhere that you can swap the columns and rows to be like myArray(6,2) then increase it to myArray(6,5) then swap back myArray(5,6).

Has anyone seen this?

Doese anyone have a work around for this?
Reply With Quote
Old 06-03-2003, 04:45 PM
Iceplug's Avatar
Iceplug Iceplug is offline

Retired Moderator
* Guru *
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583

I think you've seen wrong... you cannot redimension preserve a multidimensional array... however...
you can get away with this by creating a UDT array... and make an array of these.
Private Type IntegerArray
  Elements() As Integer
End Type
Dim IntegerAA() As IntegerArray

Redim Preserve IntegerAA(0 To 5)
For X = 0 To 5
  Redim Preserve IntegerAA(X).Elements(0 To 6)
a bit messy, but effective.

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Old 06-04-2003, 12:52 AM
Robse's Avatar
Robse Robse is offline
Senior Contributor

* Expert *
Join Date: Sep 2002
Location: Karlsruhe, Germany
Posts: 1,319

You can Redim Preserve a mulitdimensional array but you may
only Redim Preserve it's last dimension:

Dim iArray() As Integer ReDim iArray(6, 2) ReDim Preserve iArray(6, 3) 'OK ReDim Preserve iArray(7, 2) 'Error

Anyway you can always use a temporary array to copy the values
before redimming. Example:

Private Sub Form_Load() Dim m As Integer Dim n As Integer Dim iArray() As Integer 'Original array Dim iTemp() As Integer 'Temporary array ReDim iArray(6, 2) ReDim iTemp(6, 2) 'Copy original array into temp array: For m = LBound(iArray, 1) To UBound(iArray, 1) 'Loop for 1st dimension For n = LBound(iArray, 2) To UBound(iArray, 2) 'Loop for 2nd dimension iTemp(m, n) = iArray(m, n) Next n Next m 'Redim original array (destroying it) ReDim iArray(10, 2) 'Put values back from temporary array For m = LBound(iTemp, 1) To UBound(iTemp, 1) 'Loop for 1st dimension For n = LBound(iTemp, 2) To UBound(iTemp, 2) 'Loop for 2nd dimension iArray(m, n) = iTemp(m, n) Next n Next m 'iArray's first dimension is now redimmed 'and the values have been preserved. End Sub
Posting Guidelines MSDN-VB API List Use [vb]...[/vb] tags for code!
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Standards and Practices loquin Tutors' Corner 10 07-28-2006 12:16 PM
redim public array in module file danielz000 General 2 04-14-2003 07:05 AM
ReDim Preserve (subscript out of range) Virgo Game Programming 4 11-18-2002 04:43 PM
Multi dim array into Access RockingHorse Database and Reporting 2 02-03-2002 07:08 AM


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..