[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB6 ReDim  -- error 9 -- where am I going wrong?

Posted on 2009-07-16
7
Medium Priority
?
458 Views
Last Modified: 2012-05-07
This should be simple, but line 1050 is reporting error 9, subscript out of bounds.

Laugh at me if you must ... but where is my error?

Thanks!
Dim marBarControlsEnabled() As Boolean 
 
1040     If Not IsArray(marBarControlsEnabled) Then GoSub InitArray
1050     If UBound(marBarControlsEnabled, 1) < CommandBars1.Count Then GoSub InitArray
 
... now use the array
 
1200 InitArray:
    Dim iMaxBar As Integer, iMaxControl As Integer
'code to figure out the maxima ...
    
1270     ReDim Preserve marBarControlsEnabled(iMaxBar, iMaxControl)
    
1280     Return

Open in new window

0
Comment
Question by:Daniel Wilson
[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
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24869088
How is your array declared ? marBarControlsEnabled ?

If it's a one-dimension array, try this: If UBound(marBarControlsEnabled, 0)
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 24869099
you can only change 1 (the last) dimension of an array in VB6.

Dim marBarControlsEnabled() As Boolean
is a 1-dimension array, so you cannot do this:
ReDim Preserve marBarControlsEnabled(iMaxBar, iMaxControl)

0
 
LVL 32

Author Comment

by:Daniel Wilson
ID: 24869291
I need it to be 2-dimensional.

But if I start with

Dim marBarControlsEnabled(2,200) As Boolean

the Redim preserve won't compile.  It's already been dimensioned.

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 32

Author Comment

by:Daniel Wilson
ID: 24869482
I think I found it ... http://www.xtremevbtalk.com/showthread.php?t=82476

testing ...
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24869575
you will need some other method than array.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 24870341
You can only ReDim an array whose dimensions are not defined.

Dim marBarControlsEnabled() As Boolean


0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 24870417
Did you initially create the array with any dimensions?
It is possible to declare an array without specifying the dimensions.  If this is what you have done, then attempting to get a UBound on an undimensional array is going to error out.

A trick that I have done before to create a legal array, but FLAG it as "uninitiallized" is to dimensionalize it with -1.  For example, if you have a ONE dimensional array, I declare it like this...

Dim MyArray(-1 to -1) as Integer

Then I can test the array for initilization with UBound...

if UBound( MyArray, 1 ) < 0 then
   ReDim MyArray(1 to Max)
else
  ReDim Preserve MyArray(1 to Max)

The concept can be extended to multi-dimensions, just start with each diminsion from -1 to -1.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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