Solved

how do i redim a multi dimension array

Posted on 2004-03-29
8
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 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