⑴用一个数组product()来存放产品名。
⑵用另一个数组a()来存放产品名数据的下标(已经按产品名排序的)。
按产品名排序的方法是:取第一个产品名product(0),与后面所有的产品名比较一遍,如果有比第一个产品名大的,M+1,M用来计该产品名的位次。一轮结束后在a(M)元素记下第一个产品名的下标0。然后再取product(1)与其它所有产品名比较一遍,其余同第一个产品名。依次完成每一个产品名位次的计算并记录在a()数组中。
⑶最后按a()数组指定的位置取出list1中的项添加到list2中。
程序代码如下,请补充完整下面的空缺。
Dim products(100) As String '存放产品名的数组
Dim num As Integer '从数据库中读出的记录数
Private Sub Command1_Click()
Dim a(100) As Integer '存放按产品名索引的产品数组下标
Dim i As Integer, j As Integer, m As Integer 'm比当前产品名大的产品名个数
For i = 0 To 100
a(i) = 0
Next i
For i = 0 To num
m = 0
For j =
If i <> j And products(i) > products(j) Then m = m + 1
Next j
Next i
For i = 1 To num
List2.AddItem '按a数组的索引从list1中取出项添加到list2
Next i
End Sub
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim s As String, i As Integer
conn.ConnectionString = "provider=microsoft.ace.oledB.12.0;data source=" & App.Path & "\产品库.accdb "
conn.Open
Set rs.ActiveConnection = conn
rs.Open "select * from product"
num = 0
Do While Not rs.EOF And num <= 100
s = ""
For i = 1 To 5
products(num) = rs.Fields(2) '读出当前记录的产品名保存到products数组
s = s & rs.Fields(i - 1) & " ," '将一条记录的各字段内容连接成字符串
Next i
List1.AddItem s
num = num + 1
Loop
num = num - 1
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub