Option Explicit
Sub getmask(mk() As Long)
Dim i As Long
ReDim mk(1 To 30)
mk(1) = 1
For i = 2 To 30
mk(i) = mk(i - 1) * 2
Next
End Sub
Private Function number1(ByVal a As Long) As Long
number1 = 0
Do While a <> 0
number1 = number1 + 1
a = a And (a - 1)
Loop
End Function
Private Sub Command1_Click()
Dim mask() As Long
Dim t As Double
Dim data() As Long
Dim dataStr() As String
Dim dn As Long
Dim n As Long
Dim tn As Long
Dim tj() As Long
Dim str As String
Dim add As Long
Dim k As Long
Dim i As Long
Dim j As Long
Dim tmp As Long
Dim tm As Long
t = Timer
add = 300
getmask mask
dn = 0
ReDim dataStr(add - 1)
ReDim data(2, add - 1)
Open App.Path & "\b1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str
If dn > UBound(dataStr) Then
ReDim Preserve dataStr(UBound(dataStr) + add)
ReDim Preserve data(2, UBound(data, 2) + add)
End If
dataStr(dn) = str
k = 1
Do While 1
n = InStr(k, str, " ")
If n <> 0 Then
tmp = Val(Mid(str, k, n - k))
If tmp <= 30 Then
data(0, dn) = data(0, dn) Or mask(tmp)
ElseIf tmp >= 31 And tmp <= 60 Then
data(1, dn) = data(1, dn) Or mask(tmp - 30)
ElseIf tmp >= 61 And tmp <= 90 Then
data(2, dn) = data(2, dn) Or mask(tmp - 60)
End If
Else
tmp = Val(Mid(str, k, Len(str)))
If tmp > 0 And tmp <= 30 Then
data(0, dn) = data(0, dn) Or mask(tmp)
ElseIf tmp >= 31 And tmp <= 60 Then
data(1, dn) = data(1, dn) Or mask(tmp - 30)
ElseIf tmp >= 61 And tmp <= 90 Then
data(2, dn) = data(2, dn) Or mask(tmp - 60)
End If
Exit Do
End If
k = n + 1
Loop
dn = dn + 1
Loop
Close #1
tm = Val(Text1)
tn = 0
ReDim tj(4, tm - 1)
Open App.Path & "\b2.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str
k = 1
n = InStr(k, str, "-")
tmp = Val(Mid(str, 1, n - 1))
tj(3, tn) = tmp
k = n + 1
n = InStr(k, str, "=")
tmp = Val(Mid(str, k, n - 1))
tj(4, tn) = tmp
k = n + 1
Do While 1
n = InStr(k, str, " ")
If n <> 0 Then
tmp = Val(Mid(str, k, n - k))
If tmp <= 30 Then
tj(0, tn) = tj(0, tn) Or mask(tmp)
ElseIf tmp >= 31 And tmp <= 60 Then
tj(1, tn) = tj(1, tn) Or mask(tmp - 30)
ElseIf tmp >= 61 And tmp <= 90 Then
tj(2, tn) = tj(2, tn) Or mask(tmp - 60)
End If
Else
tmp = Val(Mid(str, k, Len(str)))
If tmp > 0 And tmp <= 30 Then
tj(0, tn) = tj(0, tn) Or mask(tmp)
ElseIf tmp >= 31 And tmp <= 60 Then
tj(1, tn) = tj(1, tn) Or mask(tmp - 30)
ElseIf tmp >= 61 And tmp <= 90 Then
tj(2, tn) = tj(2, tn) Or mask(tmp - 60)
End If
Exit Do
End If
k = n + 1
Loop
tn = tn + 1
If tn = tm Then
For i = 0 To dn - 1
For j = 0 To tn - 1
tmp = number1(data(0, i) And tj(0, j)) + number1(data(1, i) And tj(1, j)) + number1(data(2, i) And tj(2, j))
If tmp < tj(3, j) Or tmp > tj(4, j) Then
Exit For
End If
Next
If j = tn Then Me.List1.AddItem dataStr(i)
Next
tn = 0
ReDim tj(4, tm - 1)
End If
Loop
Close #1
Text2 = Timer - t
Text3 = Me.List1.ListCount
Text4 = Me.List2.ListCount
End Sub
老师你好:
查找按钮中的程序,我想将原:
Open App.Path & "\b1.txt" For Input As #1的数据来源改为文本框text4.text
Open App.Path & "\b2.txt" For Input As #1的数据来源改为文本框text5.text
运行时越界,烦请老师看看,谢谢!!!
问题:
data(1, dn) = data(1, dn) Or mask(tmp - 30)