从收藏夹中删除当前循环播放的商品? [英] Remove currently looped item from collection?

查看:73
本文介绍了从收藏夹中删除当前循环播放的商品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从集合中删除当前循环的项目?我收到运行时错误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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆