Option Explicit
Dim fstrNames() As String 'Dynamic declaration is better than fixed if it can change
Dim fintScores() As Integer 'Dynamic declaration is better than fixed if it can change
'You can also use a user defined type to store both values
'in one variable but we will leave that
Dim fintNumberOfStudents As Integer
Dim fintLoopCounter As Integer
Dim fintOrderPosition As Integer
Private Sub Form_Load()
'Lets assume that you are not reading your
'data from a file
ReDim fstrNames(4) 'U dont need to do this if u declare as fixed length above
fstrNames(0) = "John Smith"
fstrNames(1) = "Jenny Jones"
fstrNames(2) = "Dora Dent"
fstrNames(3) = "Roger Ramjet"
fstrNames(4) = "Kevin Kev"
'Assume whole numbers. Otherwise
'use Single or Double variables
ReDim fintScores(4) 'U dont need to do this if u declare as fixed length above
fintScores(0) = 75
fintScores(1) = 60
fintScores(2) = 80
fintScores(3) = 95
fintScores(4) = 20
'Use this if file can change in number of entries
fintNumberOfStudents = UBound(fintScores)
'Or just use fintNumberOfStudents = 4
End Sub
Private Sub Command1_Click()
'Stage 1 Display in actual order
List1.Clear
For fintLoopCounter = 0 To fintNumberOfStudents
'NB List 1 is set to SORTED = FALSE in properties
List1.AddItem fstrNames(fintLoopCounter) & vbTab & fintScores(fintLoopCounter)
Next
End Sub
Private Sub Command2_Click()
'Stage 2 Display in score order from best to worst
List1.Clear
List2.Clear 'Maybe make List2 Visible false to hide what is going on
For fintLoopCounter = 0 To fintNumberOfStudents
'NB List 2 is set to SORTED = TRUE in properties
List2.AddItem fintScores(fintLoopCounter) 'Scores are all u are sorting so leave names out
List2.ItemData(List2.NewIndex) = fintLoopCounter
Next
'Note counting backwards here
For fintLoopCounter = fintNumberOfStudents To 0 Step -1
'NB List 1 is set to SORTED = FALSE in properties
fintOrderPosition = List2.ItemData(fintLoopCounter)
List1.AddItem fstrNames(fintOrderPosition) & vbTab & fintScores(fintOrderPosition)
Next
End Sub