Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21264

High Score for a game sort Time and name

$
0
0
I can display the lowest time to highest time. But when i display the name, it's not the correct name that got that time. For example AJ should've got the 78. So how to change the order of the names?
Code:

Private Sub Command1_Click()
    Dim Seconds(1 To 5) As Integer
    Dim strName(1 To 5) As String
    Dim Num As Integer
    Dim X As Integer
   
    Num = 5
   
    Seconds(1) = 78
    Seconds(2) = 100
    Seconds(3) = 54
    Seconds(4) = 98
    Seconds(5) = 8
   
    strName(1) = "Aj"
    strName(2) = "Bob"
    strName(3) = "Cat"
    strName(4) = "Dug"
    strName(5) = "Ed"
   
    BubbleSort Seconds(), Num
    For X = 1 To 5
        List1.AddItem Str$(Seconds(X))
    Next X

    For X = 1 To 5
        List2.AddItem strName(X)
    Next X
End Sub

Code:

Public Sub BubbleSort(Num() As Integer, ByVal N As Integer)
    Dim J As Integer
    Dim K As Integer
   
    For J = 1 To N - 1
        For K = 1 To N - J
            If Num(K) > Num(K + 1) Then
                Swap Num(K), Num(K + 1)
            End If
        Next K
    Next J
End Sub

Public Sub Swap(A As Integer, B As Integer)
    Dim Temp As Integer
   
    Temp = A
    A = B
    B = Temp
End Sub


Viewing all articles
Browse latest Browse all 21264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>