VB 如何求交集

来源:百度知道 编辑:UC知道 时间:2024/09/22 15:34:06
如:Text=1,2,5,8,4....(随便输入)
for i=1 to 20
a(i)=i
next i

请问如何求得text 与a(i) 的交集?

dim jj() as integer,j as integer
dim t as string
j=0
for i=1 to 20
t=Trim(str(a(i)))
if instr(TEXT,t)>0 then
j=j+1
redim Preserve jj(j)
jj(j)=a(i)
end if
next
执行完毕后,jj()即是你所谓的交集

我测试时的代码:
Private Sub Command1_Click()
Dim a(20), i As Integer
Text = "1,2,5,8,4"
For i = 1 To 20
a(i) = i
Next i

Dim jj() As Integer, j As Integer, s As String
Dim t As String
j = 0
For i = 1 To 20
t = Trim(Str(a(i)))
If InStr(Text, t) > 0 Then
j = j + 1
ReDim Preserve jj(j)
jj(j) = a(i)
s = s & t & ","
End If
Next

MsgBox "交集:" & s
End Sub