954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Sorting an Array of String

Hey guys,

How would I go about sorting an Array of Strings, using either a selection sort or a insertion sort?

I have written an insertion sort, but i only works for integers. How can i modify it to work with strings.

Public Sub InsertionSort(ByVal numitems As Integer)
Dim currentitem, currentdataitem, comparison, shuffleitem As Integer
Dim finish As Boolean

currentitem = 1
While currentitem <= (numitems - 1)
    currentdataitem = item(currentitem)
    comparison = 0
    finish = False
    While comparison < currentitem And finish = False
        If currentdataitem < item(comparison) Then
            shuffleitem = currentitem
            While shuffleitem > comparison
                item(shuffleitem) = item(shuffleitem - 1)
                shuffleitem = shuffleitem - 1
            Wend
            item(comparison) = currentdataitem
            finish = True
        End If
        comparison = comparison + 1
    Wend
    currentitem = currentitem + 1
Wend

End Sub


Any help is appreciated.

Thanks,

Jem00

jem00
Light Poster
29 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 
vb5prgrmr
Posting Virtuoso
1,912 posts since Mar 2009
Reputation Points: 156
Solved Threads: 296
 

Thanks,
but I need to be able to do it with an insertion or selection sort.

Could you guide me as to what i should do?

jem00
Light Poster
29 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

I figured it out.
I just used the same algorithm but converted the data types.
Geez i'm stupid.
Sorry guys.

Hopefully someone else might find this thread useful.
Thanks for your help

jem00
Light Poster
29 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You