实现上述功能的VB代码如下,但加框处代码有错,请改正。
Dim a(1 To 20) As Integer ’用于保存n(n<=20)个按从小到大顺序排列的整数
‘Form_Load事件过程产生n个整数,按升序保存在数组a中,并在Text1中显示
Private Sub Form_Load()
‘代码略
End Sub
Private Sub Command1_Click()
Dim i , j , m , k As Integer
Dim x As Integer,f As Boolean ’变量f用于标记是否在数组中找到x
x = Val(Text2.Text)
i=1 :j=n : f=False
Do While i<=j And f=False
m = Fix((i+j)/2)
If a(m)=x Then f=True
If Then i=m+1 Else j=m-1 ‘(1)
Loop
If f = True Then
For k = m To n-1
‘(2)
Next k
n = n - 1
Text3.Text = ""
For k = 1 To n
Text3.Text = Text3.Text+Str(a(k))+","
Next k
Else
Text3.Text = "该数没有找到!"
End If
End Sub
以上程序段运行时,为了实现上述功能,加框处代码应改正为:
⑴;⑵。