求助!排序后重复的只显示一个值,为何?
求大神指点!请看附件,为何没有重复值时有效,
wl.rar
(16.78 KB)
有重复值时,只显示一个?Option Explicit
Dim rs As New ADODB.Recordset '定义字段
Dim rs1 As New ADODB.Recordset '定义字段
Dim cnn As New ADODB.Connection '定义数据连接
Private Sub Form_Load()
Dim strCnn$, SQL As String
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\WL.mdb;Jet OLEDB:Database Password="
cnn.Open strCnn '打开连接
rs.Open "select * from WL ", cnn, adOpenDynamic, adLockBatchOptimistic
End Sub
Private Sub Command1_Click()
Dim a As String
Dim arr(1 To 9) As Integer
Dim arr1(1 To 9) As Integer
Dim arrstr(1 To 9) As String
Dim arrstr1(1 To 9) As String
Dim I, j, T, p, q As Integer
For I = 1 To 9
a = rs.Fields(I + 1)
arr(I) = Val(a)
q = I
arr1(q) = Val(a)
arrstr(q) = rs.Fields(q + 1).Name
Next I
For q = 1 To 9
Print "+++++++++++++++"; arr1(q) & "==========>" & arrstr(q)
Next q
For I = 1 To 8
For j = 1 To 8
' If arr(j) > arr(j + 1) Then
If arr(j) > arr(j + 1) Or arr(j) = arr(j + 1) Then
T = arr(j + 1): arr(j + 1) = arr(j): arr(j) = T
End If
' arrstr(t) = arrstr(i)
'
Next j
''MsgBox t & "==>" & j
Next I
For p = 9 To 1 Step -1
For q = 1 To 9
If arr(p) = arr1(q) Then arrstr1(p) = arrstr(q)
Next q
Print arr(p) & "==========>" & arrstr1(p) ' & rs.Fields(i + 1).Name
Combo1.AddItem arrstr1(p)
'Print arrstr1(p), rs
List1.AddItem arrstr1(p)
Next p
Label1(0) = arr(9)
Label1(1) = arr(8)
Label1(2) = arr(7)
Label1(3) = arr(6)
Label1(4) = arr(5)
Label1(5) = arr(4)
Label1(6) = arr(3)
Label1(7) = arr(2)
Label1(8) = arr(1)
Text1(0) = arrstr1(9)
Text1(1) = arrstr1(8)
Text1(2) = arrstr1(7)
Text1(3) = arrstr1(6)
Text1(4) = arrstr1(5)
Text1(5) = arrstr1(4)
Text1(6) = arrstr1(3)
Text1(7) = arrstr1(2)
Text1(8) = arrstr1(1)
End Sub
运行后如下图
[此贴子已经被作者于2015-11-17 22:56编辑过]