BTW I just realized that you wanted the output to be in the sorted lists so here is the change to do that. If you want separate sorts you should be able to modify this code.
Code:Private Sub cmdSort_Click() Dim lngIndex As Long Dim bSwapped As Boolean Dim strName As String Dim intMark As Integer 'Transfer the unsorted data to the sorted lists For lngIndex = 0 To lstNames.ListCount - 1 lstSortedNames.AddItem lstNames.List(lngIndex) lstSortedMarks.AddItem lstMarks.List(lngIndex) Next ' Since we are going to loop until bSwapped = False we need to set it to ' True at the start bSwapped = True Do Until Not bSwapped ' Set it to false so if there are no values to be swapped, the ' process will end bSwapped = False ' Loop through the data. we start at 1 rather than zero because we ' have to look at the previous value For lngIndex = 1 To lstSortedNames.ListCount - 1 ' If the current value is greater than the previous one then we ' need to swap the values If lstSortedNames.List(lngIndex) > lstSortedNames.List(lngIndex - 1) Then ' Store the high values strName = lstSortedNames.List(lngIndex) intMark = lstSortedMarks.List(lngIndex) ' Replace the high values with the low values lstSortedNames.List(lngIndex) = lstSortedNames.List(lngIndex - 1) lstSortedMarks.List(lngIndex) = lstSortedMarks.List(lngIndex - 1) ' Replace the low values with the stored high values lstSortedNames.List(lngIndex - 1) = strName lstSortedMarks.List(lngIndex - 1) = intMark ' Indicate that we have swapped some data bSwapped = True ' Get out of the For/Next loop Exit For End If Next Loop End Sub




Reply With Quote