数据插入。用VB设计程序,主要功能如下:随机产生15个200以内的正整数数列,按升序排序后显示在List1列表框中,在文本框Text1中输入1个200以内的正整数,单击“插入”按钮Command1后将其插入到数列中,并保持数列仍然有序,显示在列表List2中,同时在标签Label4中显示插入的位置,程序界面如图所示。实现上述功能的VB程序代码如下,请在划线处填上合适的代码。
Dim a( 1 To 20) As Integer
Private Sub Command1_Click ( )
Dim key As Integer
key = ①
i = 1
Do While key > a ( i ) And ( i <= 1 5 )
i = i + 1
Loop
Label4.Caption = “该数插入的位置是:” + Str ( i )
If i = 16 Then
a ( i ) = key
Else
For j = 16 To i + 1 Step -1
②
Next j
a ( i ) = key
End If
List2. Clear
For i = 1 To 16
List2.AddItem a( i)
Next i
End Sub
Private Sub Form_Load( )
'随机生成15个200以内的正整数
Randomize
For i = 1 To 15
a ( i ) = Int(Rnd * 200) + 1
Next i
'将15个数从小到大排序
For i = 1 To 14
k = i
For j = i + 1 To 15
If a ( k ) > a ( j ) Then k = j
Next j
If i <>k Then
t = a(i); a( i) = a ( k ):a ( k )
End If
Next i
'将排好序的数输出在列表框Listl中
Listl.Clear
For i = 1 To 15
Listl.AddItem str ( a ( i ) )
Next i
End Sub
程序中①划线处应填入{#blank#}1{#/blank#},程序中②划线处应填入{#blank#}2{#/blank#}