#2
约定的童话2022-12-02 14:38
|
题意是:
1、access数据库中有二个表:表1(数据)、表2(条件);表1每行数据中相邻二个数据空1格,表2每行以等号为界,等号
右边数据中相邻二个数据空1格,等号左边数据区间表示包含右边的数据个数即:1到3个。
2、表2的数据每15行一组在表1中查找,将同时符合每组15行条件的数据提取到VSFlexGrid1
表1(数据)形式:
1 2 3 7 14 15 35
1 2 3 7 17 31 36
1 2 3 7 31 33 35
1 2 3 8 14 22 30
1 2 3 8 18 25 26
表2(条件)形式:
1-3=31 12 24 7 23 3 10
1-1=35 11 16 15 17 26 3
1-1=34 31 27 24 17 33 10
1-2=28 12 6 36 7 26 33
程序运行较慢,请老师帮我修改一下程序已达到快速运行的效果,谢谢!!!
Private Sub Command1_Click() '条件过滤
t = Timer
Dim arr(), drr(), crr(), tjrr(), tt, gx, tj, dn, pd As Long, brr, krr, ii As Long, kk As Long
Dim Cnn As New adodb.Connection
Dim Rst As New adodb.Recordset
Dim Rs As New adodb.Recordset
Dim SQL As String, myTable As String
Set d = CreateObject("scripting.dictionary")
Cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\数据条件源.mdb;Persist Security Info=False"
SQL = "Select * from " & "表1"
Rst.Open SQL, Cnn, adOpenKeyset, adLockOptimistic
ReDim crr(1 To Rst.RecordCount, 1 To 1)
For ii = 1 To Rst.RecordCount
crr(ii, 1) = Rst.Fields(0)
Rst.MoveNext
Next ii
SQL1 = "Select * from " & "表2"
Rs.Open SQL1, Cnn, adOpenKeyset, adLockOptimistic
ReDim arr(1 To Rs.RecordCount, 1 To 1)
For kk = 1 To Rs.RecordCount
arr(kk, 1) = Rs.Fields(0)
Rs.MoveNext
Next kk
tj = 15
ReDim tjrr(1 To tj, 1 To 12)
For i = 1 To UBound(arr)
n = n + 1
tt = Split(arr(i, 1), "=")
krr = Split(Trim(tt(1)), " ")
gs = Split(tt(0), "-")
tjrr(n, 1) = Val(gs(0))
tjrr(n, 2) = Val(gs(1))
For j = 0 To UBound(krr)
tjrr(n, 3 + j) = krr(j)
Next
If n = tj Then
For m = 1 To UBound(crr)
brr = Split(crr(m, 1), " ")
For k = 1 To tj
pd = 0
For l = 3 To UBound(krr) + 3
d(tjrr(k, l)) = m
Next
For l = 0 To UBound(brr)
If d.Exists(brr(l)) Then pd = pd + 1
Next
d.RemoveAll
If pd < CSng(tjrr(k, 1)) Or pd > CSng(tjrr(k, 2)) Then Exit For
Next
If k = tj + 1 Then dn = dn + 1: VSFlexGrid1.TextMatrix(dn, 0) = crr(m, 1)
Next
n = 0
End If
Next
MsgBox Timer - t
End Sub