Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

VB .Net 2D Array Error

  • 08-03-2006 09:14PM
    #1
    Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭


    Cant seem to figure out where im going wrong, im getting this error: 'System.IndexOutOfRangeException'
    Additional information: Index was outside the bounds of the array.
    Public Sub loc_display()
    Dim IntCount As Integer
    Dim strVar1 As String
    Dim Test As New frmTest

    IntCount = 0
    strVar1 = ""

    While IntCount < 100
    strVar1 = ArrayOfClients(IntCount, IntCount) + ", " + ArrayOfClients(IntCount, IntCount + 1) + vbNewLine
    Test.lblTest.Text = strVar1
    IntCount += 1
    strVar1 = ""
    End While
    End Sub


Comments

  • Registered Users, Registered Users 2 Posts: 1,193 ✭✭✭liamo


    You don't give any information about the size of the array which is a crucial piece of information.

    Even so, I don't think your intention is to reference a 100 x 100 element array.

    You really need to learn to use the debugger, it's your best friend at times.

    Hope this helps.

    Liam


  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    you're problem is probably with the part "ArrayOfClients(IntCount, IntCount + 1)"

    when IntCount reaches 99, IntCount + 1 is going to be 100, and a 100 element array has indexes of 0 to 99


  • Registered Users, Registered Users 2 Posts: 1,991 ✭✭✭Ziycon


    Thanks lads, i sorted it, it was a stupid little mistake by myself! While here can yous answer one more question:

    When the form loads up it gets the data from a .txt file and populates a comboBox, the problem is it only adds the first line in the .txt file and nothing else to the combobox, im sure its to do with either the combobox index or the readline not moving to the next line each time the loop iterates!

    Any ideas,thanks for the help.
    Dim sr As IO.StreamReader = New IO.StreamReader("f:\client.txt")
    Dim line As String
    Do
    cboClient.Items.Add(sr.ReadLine())
    Loop Until line Is Nothing
    sr.Close()


Advertisement