Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function strSortString(strSource As String, Optional blnSequence As Boolean = True)
' Procedure :   strSortString
' Description:  Sort a simple string into ascending or descending sequence
' By:           Chris Greaves Inc.
' Inputs:       STRING, optional SEQUENCE.
' Returns:      STRING.
' Assumes:      None.
' Side Effects: None
' Tested:       By the calls below.
    Dim str1 As String
    str1 = strSource
    Dim i As Integer
    Dim j As Integer
    For i = 1 To Len(str1) - 1
        For j = i + 1 To Len(str1)
            If Mid$(str1, i, 1) > Mid$(str1, j, 1) Then ' swap the two elements
'                MsgBox i & j
                str1 = Left$(str1, i - 1) & _
                        Mid$(str1, j, 1) & _
                        Mid$(str1, i + 1, j - i - 1) & _
                        Mid$(str1, i, 1) & _
                        Right$(str1, Len(str1) - j)
            Else
            End If
        Next j
    Next i
    strSortString = str1
'Sub TESTstrSortString()
'MsgBox strSortString("xyab")
'MsgBox strSortString("a")
'MsgBox strSortString("")
'MsgBox strSortString("aaaa")
'MsgBox strSortString("abcd")
'MsgBox strSortString("dcba")
'MsgBox strSortString("abcdb")
'MsgBox strSortString("dcbba")
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function strSortString(strSource As String, Optional blnSequence As Boolean = True)
' Procedure :   strSortString
' Description:  Sort a simple string into ascending or descending sequence
' By:           Chris Greaves Inc.
' Inputs:       STRING, optional SEQUENCE.
' Returns:      STRING.
' Assumes:      None.
' Side Effects: None
' Tested:       By the calls below.
    Dim str1 As String
    str1 = strSource
    Dim i As Integer
    Dim j As Integer
    For i = 1 To Len(str1) - 1
        For j = i + 1 To Len(str1)
            If Mid$(str1, i, 1) > Mid$(str1, j, 1) Then ' swap the two elements
'                MsgBox i & j
                str1 = Left$(str1, i - 1) & _
                        Mid$(str1, j, 1) & _
                        Mid$(str1, i + 1, j - i - 1) & _
                        Mid$(str1, i, 1) & _
                        Right$(str1, Len(str1) - j)
            Else
            End If
        Next j
    Next i
    strSortString = str1
'Sub TESTstrSortString()
'MsgBox strSortString("xyab")
'MsgBox strSortString("a")
'MsgBox strSortString("")
'MsgBox strSortString("aaaa")
'MsgBox strSortString("abcd")
'MsgBox strSortString("dcba")
'MsgBox strSortString("abcdb")
'MsgBox strSortString("dcbba")
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1