从收藏夹中删除当前循环播放的商品? [英] Remove currently looped item from collection?
问题描述
如何从集合中删除当前循环的项目?我收到运行时错误13:在wls.行上输入不匹配项.删除vl
How do I remove the currently looped item from a collection? I get run-time error 13: Type mismatch on the line wls.Remove vl
Sub FocusOnH(ByRef vls As Collection)
Dim vl As CVegetableLine
For Each vl In vls
If vl.hValue <> 0 Then
vl.volume = vl.hValue
Else
vls.Remove vl
End If
Next vl
End Sub
推荐答案
Collection.Remove()
方法采用key
(如果与.Add()
方法一起提供)或index
(默认情况下为 )作为参数,因此您无法向Remove()
方法提供用户定义的对象作为参数,该方法解释了类型不匹配错误.
Collection.Remove()
method takes either key
(if provided with the .Add()
method) or index
(by default) as parameter, so you can't provide an user-defined object as parameter to the Remove()
method which explains the Type-mismatch error.
有关 MSDN
如果要使用用户定义的类型",则应该使用Dictionary
集合.
You should really be using a Dictionary
collection if you are working with User Defined Types.
要使用迭代器来实现您想要的目标
To achieve what you want use an iterator
dim i as long
for i = Collection.Count to 1 step -1
'Collection.Remove i
next i
这篇关于从收藏夹中删除当前循环播放的商品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!