Defining an array and getting Subscript Out of Range Error 
Author Message
 Defining an array and getting Subscript Out of Range Error

So, I have a working template created by someone else.  All I needed to do
was add five additional items into an array which populates a combobox.  I
added them, but now I get the error "Subscript out of range" when the system
executes the first item in the array statement.  When I hover over the
offending statement
arrTypeOfBoard(0) = "CLA - Claims, Collections & Litigation Matters"
the tooltip says:
arrTypeOfBoard(0) = [subscript out of range]

What would be causing that error?  I haven't changed any other part of the
code and it functions fine without the addition of my five entries.

Thanks in advance for any help.
Debbie



Mon, 24 Oct 2005 03:18:56 GMT  
 Defining an array and getting Subscript Out of Range Error
Debbie

A couple of ideas:

How have you defined the array and also said how big it will be?  Also, does
your code contain, in general|declarations section of the module, Option
Base 1?

        Rob.


Quote:
> So, I have a working template created by someone else.  All I needed to do
> was add five additional items into an array which populates a combobox.  I
> added them, but now I get the error "Subscript out of range" when the
system
> executes the first item in the array statement.  When I hover over the
> offending statement
> arrTypeOfBoard(0) = "CLA - Claims, Collections & Litigation Matters"
> the tooltip says:
> arrTypeOfBoard(0) = [subscript out of range]

> What would be causing that error?  I haven't changed any other part of the
> code and it functions fine without the addition of my five entries.

> Thanks in advance for any help.
> Debbie



Mon, 24 Oct 2005 03:55:13 GMT  
 Defining an array and getting Subscript Out of Range Error
I figured it out.  The array hadn't been declared in the version of the
template I inherited, so I'm curious how it even worked.  Anyway, I added:

Dim arrTypeOfBoard(23) As String

This resolved the problem. It seems kind of counter-productive to have to
define the number of items in an array.

Thanks for chiming in.
Debbie


Quote:
> Debbie

> A couple of ideas:

> How have you defined the array and also said how big it will be?  Also,
does
> your code contain, in general|declarations section of the module, Option
> Base 1?

>         Rob.



> > So, I have a working template created by someone else.  All I needed to
do
> > was add five additional items into an array which populates a combobox.
I
> > added them, but now I get the error "Subscript out of range" when the
> system
> > executes the first item in the array statement.  When I hover over the
> > offending statement
> > arrTypeOfBoard(0) = "CLA - Claims, Collections & Litigation Matters"
> > the tooltip says:
> > arrTypeOfBoard(0) = [subscript out of range]

> > What would be causing that error?  I haven't changed any other part of
the
> > code and it functions fine without the addition of my five entries.

> > Thanks in advance for any help.
> > Debbie



Tue, 25 Oct 2005 00:22:51 GMT  
 Defining an array and getting Subscript Out of Range Error
Debbie,

I know that you have fixed your difficulty, but I can give you an
alternative approach which would avoid having to pre-set the size of the
array.  Which approach one uses, is I think, really a matter of personal
preference - not much difference in efficiency either way, AFAIK.

A further point  before I get the alternative code:  Re pre-sizing (?) the
array, you could hard code it to initially be, lets say a size of 100, ie
100 possible elements (0 to 99) - far larger than you actually need.  Then
populate the array, keeping track of the last array member used.  Then do
redim preserve arryFred(count + 1) - I think the syntax is correct, but I
haven't checked it.

The other way you could handle the array building is:

    dim vArrayContents as Variant
    dim i  as Integer

    vArrayContents = Array("........", "..........", "...........",
".............")

Then, you could treat vArrayContents as an array - thereby achieving your
initial requirement.  Also, as an extra benefit, if you want to add a new
array member, than all you need to do is add the new item to the above array
setup and you're finished :-)

eg. Of usage of this variant array

    For i = LBound(vArrayContents) To UBound(vArrayContents)
          .....
          .....
    Next

As to how the code you inherited worked, did it have an Option Explicit line
at top of the code module? - if not then the array could have *maybe* been
built on the fly without having bounds checking performed [this is just a
theory - sounds good in any case :-)]

HTH,

        Rob.


Quote:
> I figured it out.  The array hadn't been declared in the version of the
> template I inherited, so I'm curious how it even worked.  Anyway, I added:

> Dim arrTypeOfBoard(23) As String

> This resolved the problem. It seems kind of counter-productive to have to
> define the number of items in an array.

> Thanks for chiming in.
> Debbie



> > Debbie

> > A couple of ideas:

> > How have you defined the array and also said how big it will be?  Also,
> does
> > your code contain, in general|declarations section of the module, Option
> > Base 1?

> >         Rob.



> > > So, I have a working template created by someone else.  All I needed
to
> do
> > > was add five additional items into an array which populates a
combobox.
> I
> > > added them, but now I get the error "Subscript out of range" when the
> > system
> > > executes the first item in the array statement.  When I hover over the
> > > offending statement
> > > arrTypeOfBoard(0) = "CLA - Claims, Collections & Litigation Matters"
> > > the tooltip says:
> > > arrTypeOfBoard(0) = [subscript out of range]

> > > What would be causing that error?  I haven't changed any other part of
> the
> > > code and it functions fine without the addition of my five entries.

> > > Thanks in advance for any help.
> > > Debbie



Tue, 25 Oct 2005 16:31:30 GMT  
 Defining an array and getting Subscript Out of Range Error
Hi Debbie,

Have you allocated memory in the array like in:

Redim MyArray(2) As String
This allocates 3 items in a static array

For addtl info, look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr...
vastmReDim.asp

Krgrds,
Perry



Quote:
> So, I have a working template created by someone else.  All I needed to do
> was add five additional items into an array which populates a combobox.  I
> added them, but now I get the error "Subscript out of range" when the
system
> executes the first item in the array statement.  When I hover over the
> offending statement
> arrTypeOfBoard(0) = "CLA - Claims, Collections & Litigation Matters"
> the tooltip says:
> arrTypeOfBoard(0) = [subscript out of range]

> What would be causing that error?  I haven't changed any other part of the
> code and it functions fine without the addition of my five entries.

> Thanks in advance for any help.
> Debbie



Tue, 08 Nov 2005 06:33:33 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. HELP! Subscript Out Of Range error referencing array

2. Subscript out of range Error when using Arrays

3. array subscript out of range

4. subscript out of range? (floating array problem)

5. Array Subscript out of range:

6. Passing Arrays to Functions - Subscript Out of Range Problem

7. Arrays Problem SUBSCRIPT OUT OF RANGE

8. Subscript out of range error

9. Subscript out of range error

10. Subscript out of range error

11. AddShapeRecordDetected Error: Subscript out of range

12. help with subscript out of range error

 

 
Powered by phpBB® Forum Software