Results 1 to 2 of 2

Thread: Add Sort Combined TextFiles

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    1

    Question Add Sort Combined TextFiles

    Hello everyone I have a program where I am combining three text files into one. When the text files are combined. I wanted to sort it by state alphabetically in the combined file. My code doesn't seem to sort by state in my text file when combined. Where am I going wrong?

    Code:
    Public Class newsenatefrm
    
        Private Sub generatebtn_Click(sender As Object, e As EventArgs) Handles generatebtn.Click
            Dim file1() As String = IO.File.ReadAllLines("Senate113.txt")
            Dim file2() As String = IO.File.ReadAllLines("NewSen.txt")
            Dim file3() As String = IO.File.ReadAllLines("RetiredSen.txt")
            Dim combinedfiles As New List(Of String)
    
            combinedfiles.addRange(file1)
            combinedfiles.AddRange(file2)
            combinedfiles.AddRange(file3)
    
            Dim query = From line In combinedfiles
                        Let state = Split(","c)(1)
                        Let name = Split(","c)(0)
                        Let party = Split(","c)(2)
                        Order By state Ascending
                        Select name, state, party
    
            IO.File.WriteAllLines("Senate114.txt", query)
    
        End Sub
    End Class

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,725

    Re: Add Sort Combined TextFiles

    you forgot to add 'Order By'

    something like this
    Code:
        Dim query = From line In combinedfiles
                        Let state = Split(","c)(1)
                        Let name = Split(","c)(0)
                        Let party = Split(","c)(2)
                        Order By state Ascending
                        Select name, state, party Order By state Descending
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Posting Permissions

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



Click Here to Expand Forum to Full Width