Solved

how do i redim a multi dimension array

Posted on 2004-03-29
8
356 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 Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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
Course of the Month8 days, 19 hours left to enroll

617 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