Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how do i redim a multi dimension array

Posted on 2004-03-29
8
Medium Priority
?
361 Views
Last Modified: 2010-05-02
i am trying to run this piece of code.  it works fine if the array is only 1 column wide but now i need it to have 2 columns it runs 1 loop ok then stops with the error "subscript out of range"

For i = 1 To UBound(arrParagraph)
ReDim Preserve arrParagraphData(i, 2)
arrParagraphData(i, 1) = arrParagraph(i)
arrParagraphData(i, 2) = 5
cmbParagraph.AddItem arrParagraph(i)
Next
0
Comment
Question by:Marcusw
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 1000 total points
ID: 10703479
You may want to do this

ReDim Preserve arrParagraphData(UBound(arrParagraph), 2)
For i = 1 To UBound(arrParagraph)
arrParagraphData(i, 1) = arrParagraph(i)
arrParagraphData(i, 2) = 5
cmbParagraph.AddItem arrParagraph(i)
Next
0
 
LVL 3

Expert Comment

by:kenspencer
ID: 10703581
Hi,
Perhaps you should move the ReDim out of the loop.

Dim x as Integer

x = UBound(arrParagraph)
Redim Preserve arrParagraphData(x, 2)

For i = 1 To x
   arrParagraphData(i, 1) = arrParagraph(i)
   arrParagraphData(i, 2) = 5
   cmbParagraph.AddItem arrParagraph(i)
Next

Ken
0
 
LVL 3

Expert Comment

by:kenspencer
ID: 10703587
woops ... looks like I was too slow ...

Ken
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10704538
>>ReDim Preserve arrParagraphData(i, 2)<<
You cannot do that.  You will have to change it to something like:
ReDim Preserve arrParagraphData(2, i)
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10704553
Also, please followup on these old open questions:
1 02/02/2004 500 populate xml with selected item and remo...  Open Visual Basic
2 02/03/2004 500 Remote access denied using odbc 3.51.06 ...  Open Mysql
3 02/04/2004 500 add and remove elements in an existing x...  Open XML
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10704582
You can do that if you define

Dim arrParagraphData
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10705122
EDDYKT,

>>You can do that if you define<<
From BOL:
<quote>
If you use the Preserve keyword, you can resize only the last array dimension, and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array.
</quote>
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10706274
acperkins,

you are right if you've already defined that as 2 dimension array.

However, I just declare as variant
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question