Hello I need some help. I'm trying to opening a file and sorting then displaying the results in a listbox. When I run the program I get the error "Index (zero based) must be greater thatn or equal to zero and less that the size of the argument list" Here is my code. I'm getting the error on the lstDisplay.items.add line. Thanks in advance for any help or suggestions offered.

Private fmtString As String = "{0,-50},{2,8},{3,8},{4,8},{5,8}"

Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

    Dim TextFile As String
    Dim studentname As String
    Textfile = OpenFileDialog1.FileName

    Dim Student() As String = IO.File.ReadAllLines(TextFile)

    Dim StudentQuery = From Line In Student
           Let data = Line.Split(","c)
           Let Lname = data(0)
           Let Fname = data(1)
           Let Grade1 = CInt(data(2))
           Let Grade2 = CInt(data(3))
           Let Grade3 = CInt(data(4))
           Let Grade4 = CInt(data(5))
           Order By Lname
           Select Lname, Fname, Grade1, Grade2, Grade3, Grade4

    For Each StuObj In StudentQuery
        studentname = StuObj.Lname & ", " & StuObj.Fname
        lstDisplay.Items.Add(String.Format(fmtString, studentname, StuObj.Grade1, StuObj.Grade2, StuObj.Grade3, StuObj.Grade4))
    Next
End Sub

Edited 1 Year Ago by Reverend Jim: Corrected code formatting

Your problem is in Private fmtString As String = "{0,-50},{2,8},{3,8},{4,8},{5,8}". It should be

Private fmtString As String = "{0,-50},{1,8},{2,8},{3,8},{4,8}"

Hope it can help you.

Thank you very much. that worked perfectly. you are a genius. Thanks again.

Always welcome.

If it fulfils yours purpose, please mark it as solved.

Edited 1 Year Ago by Shark_1

This question has already been answered. Start a new discussion instead.