Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB .Net 2D Array Error

Options
  • 08-03-2006 9:14pm
    #1
    Registered Users Posts: 1,987 ✭✭✭


    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 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,689 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 Posts: 1,987 ✭✭✭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