VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



simple sort

by Anonymous (267 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 9th September 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

simple sort

Rate simple sort



Dim i As Long
Dim j As Long
Dim k As Integer
Dim c As String
Dim iMax As Integer
Dim A_lenght As Integer
Dim B_lenght As Integer
Dim A_char As String
Dim B_char As String
Dim A_asc As Integer
Dim B_asc As Integer

For i = LBound(sArray) To UBound(sArray)
  For j = LBound(sArray) To UBound(sArray)

    A_lenght = Len(sArray(i))
    B_lenght = Len(sArray(j))

    If A_lenght > B_lenght Then
      iMax = A_lenght
    Else
      iMax = B_lenght
    End If

    For k = 1 To iMax
      A_char = UCase(Mid(sArray(i), k, 1))
      B_char = UCase(Mid(sArray(j), k, 1))
      
      If A_char = "" Then A_char = Chr(0)
      If B_char = "" Then B_char = Chr(0)
      
      A_asc = Asc(A_char)
      B_asc = Asc(B_char)
      
      If A_asc <> B_asc Then
        Exit For
      End If
    Next

    If A_asc < B_asc Then
      c = sArray(i)
      sArray(i) = sArray(j)
      sArray(j) = c
    End If
    
    DoEvents
  Next j
Next i
End Function

Download this snippet    Add to My Saved Code

simple sort Comments

No comments have been posted about simple sort. Why not be the first to post a comment about simple sort.

Post your comment

Subject:
Message:
0/1000 characters