I looked around and couldn't find an easy way to do it so I wrote my own.

I am sure it could be done with a call to windows, but I am a very "basic" guy.

Sorry about the pun, but couldn't resist.

Function StrComp(One As String,Two As String,CaseS As UByte) As UByte

return codes:

0 if the strings are equal

1 if it should be One then Two

2 if it should be Two then One

Code: Select all

`Dim As String TheArray(1 To 100), InsertStr`

Dim As UByte LCount, x, y, CmpFlag

Declare Function StrComp(As String, As String, As Ubyte) As UByte

'Assuming that the array has data in it

'and LCount is pointing at last valid entry in array

'and InsertStr is never going to be equal to any element

x = 0

Do

x += 1

CmpFlag = StrComp(InsertStr, TheArray(x), 1)

Loop Until x = LCount Or CmpFlag = 1

LCount += 1

If CmpFlag = 1 Then 'insert inside array

y = LCount

While y > x

TheArray(y) = TheArray(y - 1)

y -= 1

Wend

TheArray(x) = InsertStr

Else 'add to end

TheArray(LCount) = InsertStr

EndIf

Function StrComp(One As String,Two As String,CaseS As UByte) As UByte

'return codes:

'0 if the strings are equal

'1 if it should be One then Two

'2 if it should be Two then One

Dim As UByte Small_Ptr, Small_Len, x

'which one is shorter?

If Len(One) > Len(Two) Then

Small_Len = Len(Two)

Small_Ptr = 2

Else

Small_Len = Len(One)

Small_Ptr = 1

EndIf

For x = 1 To Small_Len

If CaseS Then

If Asc(Mid(One, x, 1)) > Asc(Mid(Two, x, 1)) Then Return 2

If Asc(Mid(One, x, 1)) < Asc(Mid(Two, x, 1)) Then Return 1

Else

If Asc(UCase(Mid(One ,x ,1))) > Asc(UCase(Mid(Two, x, 1))) Then Return 2

If Asc(UCase(Mid(One, x, 1))) < Asc(UCase(Mid(Two, x, 1))) Then Return 1

EndIf

Next

'strings are equal to this point ....

If Len(One) = Len(Two) Then Return 0

Return Small_Ptr

End Function