小吴编写了一个查找数组中不重复数据的VB程序,功能如下:程序运行时在列表框List1中显示原始数据(存储在数组a中),单击“查找”按钮Command1后,在列表框List1中显示数组中元素值只出现一次的数据。程序运行界面如图所示。
实现上述功能的VB程序如下,但加框处代码有错,请改正。
Const n = 10 ‘数组元素的总数
Dim a(1 To n) As Integer
Private Sub Form_Load()
‘该过程对数组a进行赋值,并在列表框List1中显示,代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer,flag(1 To n) As Boolean
‘flag(i)记录第i个元素是否重复出现
For i = 1 To n ‘flag(i)=true开始假设都只出现1次
flag(i) = True
Next i
For i = 1 To n
If flag(i) Then
For j = i + 1 To n
If Then flag(i) = False: flag(j) = False ‘①
Next j
End If
Next i
For i = 1 To n
If Then List2.AddItem Str(a(i)) ‘②
Next i
End Sub
①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#}