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

what is this error message?

Hello

Does anyone know what this message could be regarding?
The application seems to fall over on the following line.
Dim variable1 As SqlString = Arraylist1(i

The first time the code runs everything is ok. The problem seems to occur when the application is run through a second time

here is the error message im getting....

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dl
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
Nov 22 '05 #1
4 1572
Bhavna <an*******@discussions.microsoft.com> wrote:
Does anyone know what this message could be regarding??
The application seems to fall over on the following line..
Dim variable1 As SqlString = Arraylist1(i)

The first time the code runs everything is ok. The problem seems to
occur when the application is run through a second time.

here is the error message im getting.....

An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative
and less than the size of the collection.


Well, the error message is pretty clear: the index you're using is out
of range. In other words, i is either too large or too small. It must
be at least 0 and also less than the number of elements in the
collection. For instance, if your collection has 5 elements, the index
you use can only be in the range 0-4.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
Cor
Hi Bhavna,

In addition to Jon, this message can also come when you have cleared your
arraylist before with something as Arraylist.clear

I hope this helps,

Cor
Nov 22 '05 #3
Hi Bhavna:
"Bhavna" <an*******@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
Hello,

Does anyone know what this message could be regarding??
The application seems to fall over on the following line..
Dim variable1 As SqlString = Arraylist1(i)

The first time the code runs everything is ok. The problem seems to occur when the application is run through a second time.
here is the error message im getting.....

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll Additional information: Index was out of range. Must be non-negative and

less than the size of the collection.
For some reason, on the second pass, something different must be happening.
Like Jon mentions, this is a pretty specific error and I'd recommend a few
things....

Every method doesn't need to have a try catch and depending on the
circumstances, you don't always want code wrapped in try/catch clauses.
However, Something should probably catch the exception somewhere up the
chain. In this instance, you aren't doing any bounds checking before you
make the reference which invites such problems. granted it's fairly
straightforward to prevent index out of range problems by really
understanding your code, but you should probably verify that you have a good
index before you reference it in the spirit of defensive programming.

Anyway, try this.....Before you call the statement which is throwing the
exception,
Debug.Assert(i <= ArrayList.Count-1) or something like If (i <=
ArrayList.Count AND i > -1) Then
Dim variable1 As SqlString = Arraylist1(i)
End If

It really depends on the whole program and coding strategy. If you opt for
a check before the reference, then you know you'll have a valid index. on
the other hand, you can check everythign under the sun which can be overkill
in situations where you can be quite sure that you have a valid index to
begin with. In such cases, using Assertions liberally will alert you of any
problems before you throw the exception.

There are a lot of things that could be happening on the second pass that
didn't happen the first time which could be causing this. It'd be impossible
to tell based on that code snippet what it could be, but check the Count of
the Array List and it will probably tip you off to the problem. If not, I'd
starting asserting preconditions throughout my code just to be sure that
everything I'm assuming to be true is a correct assumption.

HTH,

Bill

Nov 22 '05 #4
Hi Cor and Jon

Thx for both of your inputs. They have both been very useful.
I will have to look through my code now to see what is goin on with the arraylis

Many thx
Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: MFA | last post by:
Hi All Thanks to all who replied to my question dated 16/10/2003 with the same subject.. In all replies I got every one is saying that I am using cint() etc. But i am not using any convert...
6
by: Armando | last post by:
Hallo ! I habe some error in my programm,because i use <fstream.h>,I want to use <fstream> but i don´t know which fonctions i must modify in my program ? Thanks you for your help. Armando.
1
by: Naga | last post by:
Hello, Thanks for the response Oleg. Now I need to know few answers. How do I get the value of a node using the xpath. I want the value of the MessageID and ResultCode from secondxml. And using...
3
by: Odd Bjørn Andersen | last post by:
Every night at 21.30 we perform a full offline database backup. Just before the backup starts we do a db2stop/db2start. After the db2stop there is a message in the db2diag.log, and after the backup...
2
by: MLH | last post by:
I cut a mail function off the m'soft site. Has always worked. However, I would like to include error codes returned by the sendmail Fn and be able to understand what they mean. I had my first...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
12
by: craig | last post by:
Quick question for the experts... Whenever I set the Image property of a PictureBox on one of my windows forms to a PNG graphic file on my hard drive, I get the following runtime error when I...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
7
by: =?Utf-8?B?UHJpdmF0ZQ==?= | last post by:
Hey, Can some one tell me about what's wrong with the following code and what is the solution with some meaningful correction ----------------------------- class Program { static void...
1
by: John Nagle | last post by:
I'm trying some new code via GreaseMonkey, and I'm getting an occasional error on the ErrorConsole that consists of the red error icon, the full pathname of the Greasemonkey script, but no error...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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,...

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.