473,395 Members | 1,745 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,395 software developers and data experts.

Subscript out of range?

Keep getting "subscript out of range" any idea why? This function is looped btw.. Thx...

Private Sub getBday()
bDay = List1.List(nextBday)
bDayArr = Split(bDay, " - ")
Text1.Text = bDayArr(0) ' subscript out of range
Text2.Text = bDayArr(2) ' subscript out of range
nextBday = nextBday + 1
End Sub
Jan 22 '08 #1
6 12449
kadghar
1,295 Expert 1GB
Keep getting "subscript out of range" any idea why? This function is looped btw.. Thx...

Private Sub getBday()
bDay = List1.List(nextBday)
bDayArr = Split(bDay, " - ")
Text1.Text = bDayArr(0) ' subscript out of range
Text2.Text = bDayArr(2) ' subscript out of range
nextBday = nextBday + 1
End Sub
How is bDayArr defined? what is its lower bound? what is its upper bound?
debug the code and right after passing the Split part check the locals window (or just place the mouse over the array in the code if using a newer version of VB) that'll show you what's its range.
Jan 23 '08 #2
Killer42
8,435 Expert 8TB
If you haven't already, I suggest you add Option Explicit at the top of the module (if this is VB6). And turn on the Require Variable Declaration option under Editor settings to enforce it in future. Allowing VB to create variable whenever and wherever it sees fit may be slightly more convenient, but can cause tons of problems. Not knowing exactly what variables you have, their scope and so on, is not a good way to work.

If that doesn't help to clear up the bug, here are a couple of more specific points I'd like to mention:
  • Are you sure that the date you're splitting is delimited by a dash and two spaces, as specified in this piece of code?
  • How many times have you looped before hitting the error? My guess is that you've simply gone one place too far. Unless I'm mistaken, the index for List1.List() starts at 0, and so ends one lower than you might expect. In other words, if you think it goes from 1 to 12, most likely it goes from 0 to 11.

P.S. Even if you're not using VB6, the "force variable declaration" thing is still important. I'm just not sure how you turn it on in the later versions.
Jan 23 '08 #3
kadghar
1,295 Expert 1GB
(...)

P.S. Even if you're not using VB6, the "force variable declaration" thing is still important. I'm just not sure how you turn it on in the later versions.
Option Explicit On (this one is default in VB 2005)
and
Option Strict On (It doesnt allow you to mix types of variables or assume anything, e.g. if Str1 is a string, and Str1 = "25" , and Int1 is an integer, then Int1=Str1 wont be allowed, you have to make the type conversion)(this one is off by default, but it's quite useful while working with math functions)
Jan 23 '08 #4
Thx, funny, all I had to change was (2) to (1) , thx guys for making things clearer though.
Text2.Text = bDayArr(1) ' subscript out of range
Jan 23 '08 #5
Killer42
8,435 Expert 8TB
Option Explicit On...
Option Strict On ...
Hm... Option Strict sounds like it would have certain uses, but seems less important than Explicit. Of course, that may be just because I'm unfamiliar with it. In fact, it sounds like the sort of thing I try to do, and also try to encourage in others. That is, "know thy data (type)".

I think that in many cases it's not necessary to use the same data types for thigns to work properly. But if it means you have to know what data types you're using, that would be a good thing.

Anyway, thanks for the info kadghar.
Jan 23 '08 #6
Killer42
8,435 Expert 8TB
Thx, funny, all I had to change was (2) to (1) , thx guys for making things clearer though.
Text2.Text = bDayArr(1) ' subscript out of range
Glad to hear it's sorted out, then. :)

I did notice you were using 0 and 2, but didn't know enough about the data (yet) to know what you were picking out of it.

Anyway, I hope the discussion was helpful. I know I learned a bit.
Jan 23 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
5
by: Richard Delorme | last post by:
The n869 draft says: J.2 Undefined behavior The behavior is undefined in the following circumstances: -- An array subscript is out of range, even if an object is ...
8
by: VB Programmer | last post by:
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...
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...
0
by: wennerd | last post by:
I am getting a Subscript out of range after executing the following command Set oRstPick = connTemp.Execute(sSQL) It is a simple query: sSQL = "SELECT idCategory, categoryDesc, idParentCategory...
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...
6
by: Andy | last post by:
Hi all, I started developing a little app on my Mac using XCode some month ago. The app is running fine on my mac like a sharm. Now I am nearly ready and yesterday I moved the whole source code...
2
by: subramanian100in | last post by:
For vector and deque, the 'at( )' member function throws out_of_range exception if the argument to the 'at( )' function is not in range. But the subscript operator does not throw this exception...
4
by: Han | last post by:
when I exe my project in vs.net2005,I got the error following: Debug Assertion Failed! Program:........ File:c:\program files\microsoft visual studio 8\vc\include\vector Line:756 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.