Solved

how do i redim a multi dimension array

Posted on 2004-03-29
8
354 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 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
Independent Software Vendors: 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!

 
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

Independent Software Vendors: 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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

685 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