Results 1 to 14 of 14

Thread: Sort contents in a text file.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    How about something like:

    Sub cutaneous()
    Dim s As String
    
    Close #1
    Close #2
    Open "C:\TestFolder\sample.txt" For Input As #1
    Open "C:\TestFolder\samp2.txt" For Output As #2
    
    With CreateObject("System.Collections.ArrayList")
        Do Until EOF(1)
            Line Input #1, s
            .Add Trim$(CStr(s))
        Loop
        .Sort
        ary = .ToArray
        For L = LBound(ary) To UBound(ary)
            Print #2, ary(L)
        Next
    End With
    
    Close #1
    Close #2
    End Sub
    Last edited by Aussiebear; 03-22-2023 at 04:52 AM. Reason: Adjusted code tags
    Have a Great Day!

Posting Permissions

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