VS 2012 reading an textfile to an array, and then sorting.-VBForums
Results 1 to 3 of 3

Thread: reading an textfile to an array, and then sorting.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Posts
    2

    Resolved reading an textfile to an array, and then sorting.

    I have a text file that is populated with

    08 name :tt
    11 name :nn
    07 name :kk

    I would like the read the whole text file to an array, and then sort it, afterwards displaying it into a list box. i have tried

    listArrays.Items.Clear()
    Dim content As String
    Dim lines As New ArrayList
    Dim sr As System.IO.StreamReader
    ' read the file's lines into an ArrayList
    Try
    sr = New System.IO.StreamReader("G:\ControlleAssesmentClass\Class1.txt")
    Do While sr.Peek() >= 0
    lines.Add(sr.ReadLine())
    Loop
    lines.Sort()
    lines.Reverse()
    Finally
    If Not sr Is Nothing Then sr.Close()
    End Try
    listArrays.Items.Clear()
    listArrays.Sorted = True
    listArrays.Items.AddRange(lines.ToArray)

    End Sub
    `
    but it does not work, as it only sorts the file but doesnt display it in its reverse order. can anyone help please, thank you.
    Share on Google+

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,474

    Re: reading an textfile to an array, and then sorting.

    lines = lines.Reverse()
    Share on Google+

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,159

    Re: reading an textfile to an array, and then sorting.

    I am closing the thread as you've already asked the question on this thread: http://www.vbforums.com/showthread.p...ting-the-array

    Please do not post multiple threads.
    Share on Google+

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.