473,951 Members | 5,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subscript out of range?

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

Private Sub getBday()
bDay = List1.List(next Bday)
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 12498
kadghar
1,295 Recognized Expert Top Contributor
Keep getting "subscript out of range" any idea why? This function is looped btw.. Thx...

Private Sub getBday()
bDay = List1.List(next Bday)
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 Recognized Expert Expert
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 Recognized Expert Top Contributor
(...)

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)(thi s one is off by default, but it's quite useful while working with math functions)
Jan 23 '08 #4
brandon01
3 New Member
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 Recognized Expert Expert
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 Recognized Expert Expert
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
5670
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 -------------------------------------------------------- 2Sports 'trouble shooting illustrated 'trouble shooting Newsstand 'trouble shooting
5
3449
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 apparently accessible with the given subscript (as in the lvalue expression a given the declaration
8
8528
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 don't know why. Briefly.... I have an array of Variants dimmed as this: Global gMyConnection() As Variant I redim it later like this:
51
23856
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 10018-clc.c: In function `main': 10018-clc.c:22: warning: array subscript has type `char' I don't like warnings ... or casts.
0
2139
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 FROM categories WHERE idCategory <> 1;" My connection string looks like this: connString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &server.MapPath("../database/comersus.mdb")&";" set connTemp=server.createobject("adodb.connection")
6
2746
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 based on the const type. Infact if I use the Array on the left side i.e like a1 = 111 then it uses the first while if I use cout << a1 it uses the second... why????
6
11104
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 to a Windows PC and build it in MS VC++. Now I got a lot of "vector subscript out of range" assertion errors and I don't know why because on my Mac it is working without any error. What does the Mac with this problems and what is the magic behind...
2
2329
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 for the same situation. My question: Why can't the subscript operator itself throw the out_of_range exception in which case the 'at ( )' member function may not be needed ?
4
7121
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 Expression:vector subscript out of range.
0
10174
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11607
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11203
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10704
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9913
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6360
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3565
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.