关于在VB中求交集的问题

wuyuesisi 2004-03-29 08:26:04
求VB中对两个集合判断是否为空然后删除重复的内容,并取交集的方法
...全文
264 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
海牛 2004-04-04
  • 打赏
  • 举报
回复
9494,,自己写循环处理吧!!!
northwolves 2004-04-04
  • 打赏
  • 举报
回复
Function intersection(ByVal x As Collection, ByVal Y As Collection) As Collection
Dim I As Long, J As Long, z As New Collection, repeat As Boolean
If x.Count * Y.Count = 0 Then Set intersection = Nothing
Set z = x
For I = z.Count To 1 Step -1
For J = 1 To Y.Count
repeat = False
If Y(J) = z(I) Then repeat = True: Exit For
Next
If repeat = False Then z.Remove I
Next
Set intersection = z
Set z = Nothing
End Function


Private Sub Command1_Click()
Dim A As New Collection
Dim B As New Collection
Dim C As New Collection

Debug.Print " COLLECTION A:"
For I = 1 To 26
A.Add Chr(I + 60)
Debug.Print A(I)
Next


Debug.Print " COLLECTION B:"
For I = 1 To 50
B.Add Chr(I + 64)
Debug.Print B(I)
Next

Set C = intersection(A, B)
Debug.Print " intersection(A AND B):"
For I = 1 To C.Count
Debug.Print C(I)
Next
End Sub
wumy_ld 2004-04-04
  • 打赏
  • 举报
回复
dim i,j as integer
for i=集合1.Count to 1 step -1
for j=1 to 集合2.Count
if 集合1(i)=集合2(j) then
集合1.Remove i
endif
next j
next i
wuyuesisi 2004-04-03
  • 打赏
  • 举报
回复
我不是要写数据库…………
Jockey 2004-04-01
  • 打赏
  • 举报
回复
删除可以用:delete from ..... where ....
查询可以:select UtblName from where ... in (....)
chenziteng 2004-03-31
  • 打赏
  • 举报
回复
笨办法,封装Collection对象形成集合类,在内部用循环比较实现判断.

比用数据库直接吧:)
kmzs 2004-03-31
  • 打赏
  • 举报
回复
什么类型的集合?
wuyuesisi 2004-03-31
  • 打赏
  • 举报
回复
问题在于所用集合未知大小
华芸智森 2004-03-29
  • 打赏
  • 举报
回复
我建议用数据库做.将数据插入两个表中再SELECT ..FORM ..WHERE..IN... 即可.

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧