Type NumberSet
A As Double
B As Double
C As Double
D As Double
End Type
Public Sub TheSub()
Dim numbers(0 To 199) As Double
numbers(0) = 123
numbers(1) = 456
'
' and so on.
'
'iterators
Dim ai As Integer
Dim bi As Integer
Dim ci As Integer
Dim di As Integer
'data set
Dim x() As NumberSet
'temp record holder
Dim ns As NumberSet
Dim count As Integer
count = 0
'simulate the select query
For ai = LBound(numbers) To UBound(numbers)
For bi = LBound(numbers) + 1 To UBound(numbers)
For ci = LBound(numbers) + 2 To UBound(numbers)
For di = LBound(numbers) + 3 To UBound(numbers)
'fill the record
With ns
.A = numbers(ai)
.B = numbers(bi)
.C = numbers(ci)
.D = numbers(di)
'test record
If .A + .B + .C + .D = 2341.42 Then
'append to the data set
ReDim Preserve x(0 To count)
x(count) = ns
count = count + 1
End If
End With
Next di
Next ci
Next bi
Next ai
'iterate through data set and print results
For i = LBound(x) To UBound(x)
ns = x(i)
With ns
Debug.Print .A & ", " & .B & ", " & .C & ", " & .D
End With
Next i
End Sub
不是最有效的……但是试图遵循原始代码的流程。它将运行缓慢,因为它就像野蛮的循环(大约需要4分钟)。也许通过ADO/DAO使用临时的数据库/访问表可以帮助您使用SQL。