473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
8 8477
* "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
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
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
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lukelrc | last post by:
Hi, I have some VBscript that lists the files in a folder. What i want to do is populate an array with the file names and then use that array to populate a list box. I have got as far as...
20
by: andy.rich | last post by:
I am getting the following error and I do not know why. Can anyone help? -------------------------------------------------------- this is what appears on the screen...
2
by: jv | last post by:
I have a form that is used every day to create quotes. However, every 2 weeks or so a user would randomly get an error 9 - subscript out range message. I'm not using any array in this form. Does...
4
by: winnerpl | last post by:
Hey guys I'm trying to get a magic square but I'm stuck with it printing out only 1's and 0's in random places. Hope you experts can can provide some input on what I'm doing wrong. #include...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
6
by: toch3 | last post by:
i am writing a c program that is basically an address book. the only header we are using is #include<stdio.hwe are to use a global array, loops, and pointers. we are to have a menu at the...
6
by: josh | last post by:
Hi I've a dubt! when we have overloaded functions the compiler chooses the right being based on the argument lists...but when we have two subscript overloaded functions it resolves them being...
4
by: Annalyzer | last post by:
Can anyone see what's wrong with this code: Private Sub Command278_Click() On Error GoTo Err_Command278_Click Dim stDocName As String Dim whereArray() Dim stLinkCriteria,...
1
by: tomaz | last post by:
i have an array for each mailbox. if i ask the array of mailbox 1,2,3,4... it returns a "1" if there are unread messages. If there are no unread messages i receive "". (empty) Yet, the moment I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.