By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,538 Members | 2,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,538 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
* "VB Programmer" <gr*********@go-intech.com> scripsit:
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!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
Thanks. I posted there too.

Still, if anyone can help, I would appreciate it!

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bu************@ID-208219.news.uni-berlin.de...
* "VB Programmer" <gr*********@go-intech.com> scripsit:
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!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #3

P: n/a
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 wrote:
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?


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #4

P: n/a
"VB Programmer" <gr*********@go-intech.com> wrote...
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

Nov 20 '05 #5

P: n/a
Thanks for your help and advice!

"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
"VB Programmer" <gr*********@go-intech.com> wrote...
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

Nov 20 '05 #6

P: n/a
Thanks alot.

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
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 wrote:
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?


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #7

P: n/a
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!

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
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?

Nov 20 '05 #8

P: n/a
OHM,

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

Rob
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.