VB6比较列表1和列表2,并从列表2中删除不需要的项目

VB6比较列表1和列表2,并从列表2中删除不需要的项目,vb6,Vb6,我试图比较vb6中的2个listbox,list2项应该与list1中的项匹配,然后从list2中删除不匹配的字符串 清单1项目: ls-05 ls-06 ls-12 mg_01.rom mg_02.rom mg_05.rom mg_06.rom mg_m07.rom mg_m08.rom mg_m09.rom mg_m10.rom mg_m11.rom mg_m12.rom mg_m13.rom mg_m14.rom 清单2项目: ls-05 ls-05.12e ls-06 ls-06.10

我试图比较vb6中的2个listbox,list2项应该与list1中的项匹配,然后从list2中删除不匹配的字符串

清单1项目:

ls-05
ls-06
ls-12
mg_01.rom
mg_02.rom
mg_05.rom
mg_06.rom
mg_m07.rom
mg_m08.rom
mg_m09.rom
mg_m10.rom
mg_m11.rom
mg_m12.rom
mg_m13.rom
mg_m14.rom
清单2项目:

ls-05
ls-05.12e
ls-06
ls-06.10e
ls-11
ls-11.2l
ls-12
ls-12.7l
mg_01.rom
mg_02.rom
mg_05.rom
mg_06.rom
mg_m07.rom
mg_m07.rom2
mg_m08.rom
mg_m08.rom3
mg_m09.rom
mg_m09.rom2
mg_m10.rom
mg_m10.rom3
mg_m11.rom
mg_m11.rom0
mg_m12.rom
mg_m12.rom1
mg_m13.rom
mg_m13.rom0
mg_m14.rom
mg_m14.rom1
按钮代码:

For ii = List1.ListCount - 1 To 0 Step -1
    For i = List1.ListCount - 1 To 0 Step -1
        If List1.List(i) = List2.List(ii) Then Exit For ' no need to keep looping, its a match. i will be > -1
    Next
    If i = -1 Then ' all items in list1 were searched, but no matches found, so remove it
        List2.RemoveItem ii
    End If
Next
因此,我所追求的最终结果是list2,它应该有相同的项来删除其他不匹配的垃圾字符串。

使用strings和InStrB()函数:

dim lstitm as string, str2 as string, count as integer

count = list2.listcount

for i = 0 to count - 1
  str2 = str2 & list2.list(i) & ";"
next i

list2.clear

count = list1.listcount

for i = 0 to count -1
 lstitm = list1.list(i)
 if instrb(1,str2,lstitm) <> 0 then list2.additem lstitm
next i
dim lstitm为字符串,str2为字符串,计数为整数
count=list2.listcount
如果i=0,则计数为-1
str2=str2和列表2。列表(i)和“
接下来我
清单2.2清除
count=list1.listcount
如果i=0,则计数为-1
lstitm=list1.list(i)
如果instrb(1,str2,lstitm)为0,则list2.additem lstitm
接下来我

不应该
For ii=List1.ListCount-1到0步骤-1
For ii=List2.ListCount-1到0步骤-1ie
List2
不清楚您的实际问题是什么?你是在找代码审查吗?