Help with IndexOutOfRange Exception - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8) +---- Thread: Help with IndexOutOfRange Exception (/showthread.php?tid=505) |
Help with IndexOutOfRange Exception - FtDLulz - 04-04-2012 I keep getting this error when trying to run my program and click on something in a listbox. IndexOutOfRangeException was unhandled Index was outside the bounds of the array. My Code and the part where it errors (Marked with ><): Code: Dim conn As MySqlConnection I tried rank with an INT too. In the database: 0 = ID 1 = Username 2 = Password 3 = Rank Re: Help with IndexOutOfRange Exception - brandonio21 - 04-05-2012 All that really has to be looked at are these segments of code: Code: writer.Write(data(3).ToString + "=" + data(0).ToString) Code: Dim splitread() As String = reader.ReadToEnd.Split("=") Code: lbl_rank1.Text = "Rank: " + splitread(3).ToString So what you are doing is writing two things into a text file, separated by an equals sign. Then you are reading that text file, and splitting up the elements by the equals sign. So you are splitting them up as
So with that in mind, you then try to get splitread(3).ToString. This throws an error because in the list, as we just saw, there are only items with an index of 0 and 1, and an item with the index of 3 does not exist. Re: Help with IndexOutOfRange Exception - FtDLulz - 04-05-2012 So I should change the 3 to a 0 and the 0 to a 1 to get it to display correctly? Thanks for explaining that, was looking all over <!-- s --><img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt="" title="Very Happy" /><!-- s --> Re: Help with IndexOutOfRange Exception - brandonio21 - 04-06-2012 Hm, well I don't know how your database tables are constructed, but just mess around until you get the result that you want! |