HELP: Subscript out of range error (array) - CONFUSED!

  • Thread starter Thread starter Herfried K. Wagner [MVP]
  • Start date Start date
H

Herfried K. Wagner [MVP]

* "VB Programmer said:
I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for
version 6....

microsoft.public.vb.* is the place you are looking for!
 
I dont remember if VB6 have upper bound initialisers of not ?, In VB.NET the
subscript on initialisation is the upper bound so for example myarray(7)
would have 8 elements ( 0 - 7 ).

In VB6, If this is the number of elements rather than the upper bound ( get
my drift ) then for an initialisation of myarray(7), the elements would be
( 0 - 6 ).

HTH - Regards - OHM
 
VB Programmer said:
Thanks. I posted there too.
Still, if anyone can help, I would appreciate it!

Hopefully I can help... first there doesn't appear to be anything wrong
with the code you've posted except that you should be able to intialize
element 66 also.

Which leads me to believe the code may not be exactly has you posted. In
these situations I'll tell you what I do. Eliminate anything else that
could be the cause of the problem, get it to work as expected and then add
code back a few lines at a time.

So... in your case comment out the class assignments. Since you have the
array as variants just plop a string in it something like:

gMyConnection(i) = "test " & CStr(i)

Have the loop fill the array and then have a second loop print the array
elements. It works for me so I can't imagine it won't work for you.

Tom
 
SORRY ABOUT THE DATE/TIME OF THIS THREAD. I DIDN'T REALIZE BY CLOCK WAS
AHEAD BY 1 DAY. I HAVE FIXED IT. SORRY AND THANKS ONCE AGAIN EVERYONE!
 
OHM,

VB6 works the same way as .Net does in this regard. MyArray(7) gives you
elements with indexes 0-7 (8 elements).

Rob
 
I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for
version 6....

I need help for something that should be simple. I keep getting a
"subscript out of range" error and don't know why. Briefly....

I have an array of Variants dimmed as this:
Global gMyConnection() As Variant

I redim it later like this:
ReDim gMyConnection(66)

In a FOR loop (For i = 0 to 65) I am doing this:
Set gMyConnection(i) = New MyClass
* NOTE: There is no class_initialize in the MyClass class.

On this "Set" line, when i = 65, I keep getting an "Error 9 subscript out of
range" error. It works for i = 0 to i = 64.

Any ideas?
 
Thanks for your help and advice!

Tom Leylan said:
Hopefully I can help... first there doesn't appear to be anything wrong
with the code you've posted except that you should be able to intialize
element 66 also.

Which leads me to believe the code may not be exactly has you posted. In
these situations I'll tell you what I do. Eliminate anything else that
could be the cause of the problem, get it to work as expected and then add
code back a few lines at a time.

So... in your case comment out the class assignments. Since you have the
array as variants just plop a string in it something like:

gMyConnection(i) = "test " & CStr(i)

Have the loop fill the array and then have a second loop print the array
elements. It works for me so I can't imagine it won't work for you.

Tom
 
Thanks alot.

One Handed Man said:
I dont remember if VB6 have upper bound initialisers of not ?, In VB.NET the
subscript on initialisation is the upper bound so for example myarray(7)
would have 8 elements ( 0 - 7 ).

In VB6, If this is the number of elements rather than the upper bound ( get
my drift ) then for an initialisation of myarray(7), the elements would be
( 0 - 6 ).

HTH - Regards - OHM
 
Back
Top