【加试题】某公司要对数据进行处理:原始数据从数据库中读取(数据存放在第一个字段,记录数最多为100条),然后进行降序排列并去重复值处理,最后输出,如原始数据为5,2,5,2,3,则处理后输出结果为5,3,2。该程序代码如下所示。
Dim n As Integer,a(100)As Integer,max As Integer
Private Sub
Form_Load() ‘读取原始数据
Dim conn As New
ADODB.Connection.rs As New ADODB.Recordset
Dim i As
Integer
conn.ConnectionString=”Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=”&App.Path&。”\student.accdb”
conn.Open
Set rs.ActiveConnection=conn
rs.Open“SELECT*FROM DF”
i=0:max=0
Do While Not rs.EOF
i=i+1:n=i
a(i)= ‘①
If a(i)>max Then max=a(i)
rs.MoveNext
Loop
rs.Close:conn.Close
End Sub
Private Sub Command1_Click() ‘去重复值排序
Const t=max
Dim i As Integer,b(t)As Integer
For i=1 To n
B(a(i))=b(a(i))+1
Next i
For i=1 To t
If Then List1.AddItem Str(t-i+1) ‘②
Next i
End Sub