Consulting

Results 1 to 14 of 14

Thread: Sort contents in a text file.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    It is best to start your own threads. You can always post a link to a thread that might be relevant.

    When pasting code, please paste between code tags. Click the # icon to insert tags.

    These days, most Microsoft Windows computers will have the framework files installed.

    Sub ken()  
      Dim a() As Variant
      
      a() = Array(5, 6, 1, 11)
      MsgBox Join(a, vbLf)
      
      a() = ArrayListSort(a)
      MsgBox Join(a, vbLf)
      
      a() = ArrayListSort(a, False)
      MsgBox Join(a, vbLf)
    End Sub
    
    Function ArrayListSort(sn As Variant, Optional bAscending As Boolean = True)
        With CreateObject("System.Collections.ArrayList")
            Dim cl As Variant
            For Each cl In sn
                .Add cl
            Next
             
            .Sort 'Sort ascendending
            If bAscending = False Then .Reverse 'Sort and then Reverse to sort descending
            ArrayListSort = .toarray()
        End With
    End Function
    Last edited by Kenneth Hobs; 09-21-2015 at 07:02 PM.

Posting Permissions

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