【加试题】某人编写了一个VB程序对一组随机数进行排名。程序运行时,产生10个随机整数存数组d中,并在列表框List 1中显示,单击按钮Command 1,在列表框List1 2中显示降序排序后数据及名次,若数值相同则名次相同。实现上述功能的VB 代码如下,但加框处代码有错,请改正。
Const n
= 10
Dim d(1 To n) As Integer, pm(1 To n) As Integer
Private Sub Form_Load()
'代码略,本过程功能:产生10个随机整数存数组d中,并在列表框list1 中显示。
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, t As
Integer
i = 1
Do While i <= n - 1
k = i
For j = i + 1 To n
If Then k = j ‘①
Next j
If i <> k Then t = d(i): d(i) = d(k): d(k) = t
i = i + 1
Loop
pm(1) = 1
For i = 2 To n
If Then ‘②
pm(i) = i
Else
pm(i) = pm(i - 1)
End If
Next i
For i = 1 To n
List2.AddItem Str(i) +" " +Str(d(i)) + " " + "第" + Str(pm(i)) + "名"
Next I
End Sub
①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#}