李华编写了实现上述功能的程序,程序功能如下:程序运行时,在文本框Text1中输入n(1<=n<=10)单击“产生”按钮Command1产生n×n个随机数,随机数的范围为[0,9],随机存储在数组a中,并以矩阵的形式在列表框List1上显示。单击“排序”按钮Command2,对矩阵以“行”为单位进行升序排序,并在列表框List2输出排序后的矩阵。在程序运行界面如下图所示。
实现上述功能的VB程序如下,请在划线处填入合适的代码。
Dim n As Integer
Dim a(1 To 100) As Integer
Private Sub Command1_Click( )
Dim i As Integer, s As String
s = ""
For i = 1 To n * n
s = s + Str(a(i))
If i Mod n = 0 Then
List1.AddItem s
s = ""
End If
Next i
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, t As Integer
Dim s As String
s = ""
For i = 1 To n * n
k = i
For j = i + 1 To
If a(j) < a(k) Then k = j
Next j
If k <> i Then t = a(k):a(k) = a(i):a(i) = t
If i Mod n = 0 Then
List2.AddItem s
s = ""
End If
Next i
End Sub