Here is some code that will sort an array, I can show you how to modify it to your needs:
Public Function SortArray(ByRef TheArray As Variant)
Sorted = False
Do While Not Sorted
Sorted = True
For x = 0 To UBound(TheArray) - 1
If TheArray(x) > TheArray(x + 1) Then
Temp = TheArray(x + 1)
TheArray(x + 1) = TheArray(x)
TheArray(x) = Temp
Sorted = False
End If
Next x
Loop
SortArray = TheArray
End Function
Sub UseSortArray()
'Make an array
a = "1,2,3,8,3,5,6"
b = Split(a, ",")
'Sort it
c = SortArray(b)
d = Join(c, ",")
End Sub
Main Topics
Browse All Topics





by: dovidfPosted on 2007-01-07 at 16:10:23ID: 18263778
For a quick and dirty (inefficient) solution use a bubble sort as per the code below. Put your numbers into the array.
// array of integers to hold values
private int[] a = new int[100];
// number of elements in array
private int x;
// Bubble Sort Algorithm
public void sortArray()
{
int i;
int j;
int temp;
for( i = (x - 1); i >= 0; i-- )
{
for( j = 1; j <= i; j++ )
{
if( a[j-1] > a[j] )
{
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
}
}
}
}