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

More of "Index was outside the bounds of the array"

P: n/a
Herfried and Cor:-

I used tracing and actually tracked down the code that was causing the
problem most likely. I wonder if you wanted to comment on it.

Also I wonder if there is a better way of testing if there is data than
testing the length of the xml string I used as stringreader to create the
dataset, but thats a side issue.

I think I tried isdbnull and is nothing and stuff like that and they cause
run time errors if there isnt any data, in other areas of code I have had
problems with using it so found this a reasonable way of ensuring the string
returned with data that must mean there was data - as I have a catch anyway
so if any errors occur, it will quit before it gets to these string length
testing parts of code.

Anyway back to the actual problem. I THINK its because the application
usually throws a comma in the field1, but I can reproduce the error if I
don't.
I THINK I either need to change my selection of fields (and get less
complicated and get data from seperate fields that might contain same data )
or test for an index of comma in the file, and do something different if
there is no comma.

If Len(xmlstr1) > 25 Then
For intCounter = 0 To dataset1.Tables("result").Rows.Count - 1
dt.Rows.Add(CreateRow("[" +
dataset1.Tables("result").Rows(intCounter).Item("f ield1").split(",")(1).subs
tring(1, 1).toupper +
dataset1.Tables("result").Rows(intCounter).Item("f ield1").split(",")(0).subs
tring(0, 1).toupper + "]:" +
dataset1.Tables("result").Rows(intCounter).Item("f ield1"),
dataset1.Tables("result").Rows(intCounter).Item("f ield2"), dt))
Next
End If
"An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception
can be identified using the exception stack trace below.

Stack Trace:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Array.InternalGetValue(Int32 index1, Int32 index2, Int32 index3)
+0
System.Array.GetValue(Int32 index) +32
Microsoft.VisualBasic.CompilerServices.LateBinding .LateIndexGet(Object o,
Object[] args, String[] paramnames) +187
sharedcal.ShareCal.o() +655
sharedcal.ShareCal.Page_Load(Object o, EventArgs e) +799
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750


Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

Two ways it could fail with that error. 1 no comma in string split
will only create an item 0 in the array. Second the first letter in a
string is at position 0 so if the string isnt 2 characters long
substring(1,1) will fail. It is also better to use & to combine strings
than +.

Dim a() As String = "No commas here".Split(",".ToCharArray)

Debug.WriteLine(a(1)) ' Index outside of bounds error here

Ken
---------------------
"Antoine" <mf****@dsl-spam.pipex.com> wrote in message
news:10*************@corp.supernews.com...
Herfried and Cor:-

I used tracing and actually tracked down the code that was causing the
problem most likely. I wonder if you wanted to comment on it.

Also I wonder if there is a better way of testing if there is data than
testing the length of the xml string I used as stringreader to create the
dataset, but thats a side issue.

I think I tried isdbnull and is nothing and stuff like that and they cause
run time errors if there isnt any data, in other areas of code I have had
problems with using it so found this a reasonable way of ensuring the string
returned with data that must mean there was data - as I have a catch anyway
so if any errors occur, it will quit before it gets to these string length
testing parts of code.

Anyway back to the actual problem. I THINK its because the application
usually throws a comma in the field1, but I can reproduce the error if I
don't.
I THINK I either need to change my selection of fields (and get less
complicated and get data from seperate fields that might contain same data )
or test for an index of comma in the file, and do something different if
there is no comma.

If Len(xmlstr1) > 25 Then
For intCounter = 0 To dataset1.Tables("result").Rows.Count - 1
dt.Rows.Add(CreateRow("[" +
dataset1.Tables("result").Rows(intCounter).Item("f ield1").split(",")(1).subs
tring(1, 1).toupper +
dataset1.Tables("result").Rows(intCounter).Item("f ield1").split(",")(0).subs
tring(0, 1).toupper + "]:" +
dataset1.Tables("result").Rows(intCounter).Item("f ield1"),
dataset1.Tables("result").Rows(intCounter).Item("f ield2"), dt))
Next
End If
"An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception
can be identified using the exception stack trace below.

Stack Trace:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Array.InternalGetValue(Int32 index1, Int32 index2, Int32 index3)
+0
System.Array.GetValue(Int32 index) +32
Microsoft.VisualBasic.CompilerServices.LateBinding .LateIndexGet(Object o,
Object[] args, String[] paramnames) +187
sharedcal.ShareCal.o() +655
sharedcal.ShareCal.Page_Load(Object o, EventArgs e) +799
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750

Nov 21 '05 #2

P: n/a
Antoine,

In advance I think that it is for yourself not good to address these
questions to me alone (I cannot speak for Herfried).

Some things can easily be answered by me, others questions by others,
therefore it is a community, so it is better not to address questions to
special people.

When I was you I would place this question again, without that Cor and
Herfried to give yourself a better change. And than show what is that
createrow, because I don't know that as a function to create a datarow.
(However maybe others do)

Just to help nothing offended or whatever,

Cor


Nov 21 '05 #3

P: n/a
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eU**************@TK2MSFTNGP11.phx.gbl...
Antoine,

In advance I think that it is for yourself not good to address these
questions to me alone (I cannot speak for Herfried).

Some things can easily be answered by me, others questions by others,
therefore it is a community, so it is better not to address questions to
special people.

When I was you I would place this question again, without that Cor and
Herfried to give yourself a better change. And than show what is that
createrow, because I don't know that as a function to create a datarow.
(However maybe others do)

Just to help nothing offended or whatever,

Cor


Absolutely none taken.

Thanks for you advice, I thik I understand now to redo the code anyway, and
access a completely differnent call that allows seperate fields. The one I
was doing only brought out a database "combined" field, which of course with
such combinations would just lead to complicated code.

Thanks!
Nov 21 '05 #4

P: n/a

Thanks I will take to heart your info particulary about using &

I thik I understand now to redo the code anyway, and access a completely
differnent call that allows seperate fields. The one I was doing only
brought out a database "combined" field, which of course with such
combinations would just lead to complicated code because of combinations of
"," white space etc etc

Thanks!

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi,

Two ways it could fail with that error. 1 no comma in string split will only create an item 0 in the array. Second the first letter in a
string is at position 0 so if the string isnt 2 characters long
substring(1,1) will fail. It is also better to use & to combine strings
than +.

Dim a() As String = "No commas here".Split(",".ToCharArray)

Debug.WriteLine(a(1)) ' Index outside of bounds error here

Ken
---------------------
"Antoine" <mf****@dsl-spam.pipex.com> wrote in message
news:10*************@corp.supernews.com...
Herfried and Cor:-

I used tracing and actually tracked down the code that was causing the
problem most likely. I wonder if you wanted to comment on it.

Also I wonder if there is a better way of testing if there is data than
testing the length of the xml string I used as stringreader to create the
dataset, but thats a side issue.

I think I tried isdbnull and is nothing and stuff like that and they cause
run time errors if there isnt any data, in other areas of code I have had
problems with using it so found this a reasonable way of ensuring the string returned with data that must mean there was data - as I have a catch anyway so if any errors occur, it will quit before it gets to these string length
testing parts of code.

Anyway back to the actual problem. I THINK its because the application
usually throws a comma in the field1, but I can reproduce the error if I
don't.
I THINK I either need to change my selection of fields (and get less
complicated and get data from seperate fields that might contain same data ) or test for an index of comma in the file, and do something different if
there is no comma.

If Len(xmlstr1) > 25 Then
For intCounter = 0 To dataset1.Tables("result").Rows.Count - 1
dt.Rows.Add(CreateRow("[" +
dataset1.Tables("result").Rows(intCounter).Item("f ield1").split(",")(1).subs tring(1, 1).toupper +
dataset1.Tables("result").Rows(intCounter).Item("f ield1").split(",")(0).subs tring(0, 1).toupper + "]:" +
dataset1.Tables("result").Rows(intCounter).Item("f ield1"),
dataset1.Tables("result").Rows(intCounter).Item("f ield2"), dt))
Next
End If
"An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Array.InternalGetValue(Int32 index1, Int32 index2, Int32 index3)
+0
System.Array.GetValue(Int32 index) +32
Microsoft.VisualBasic.CompilerServices.LateBinding .LateIndexGet(Object o, Object[] args, String[] paramnames) +187
sharedcal.ShareCal.o() +655
sharedcal.ShareCal.Page_Load(Object o, EventArgs e) +799
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.