如何避免vb6集合中的重复值 [英] how to avoid duplicate values in collection from vb6
问题描述
嗨我有以下值我想在集合中添加这些值,如果已经在集合消息中的值显示已经在您的集合中添加了这个值。
`Dim OrdLines As New Collection`
`OrdLines.Add(111,这是第一项)`
`OrdLines.Add(222,这是第二项)`
`OrdLines.Add(333,这是第三项)`
`OrdLines.Add(444,这是第四项)`
请指导我如何避免集合中的重复值
提前感谢
hi I have following values I want to add these in collection if the values already in collection message show this is already added in your collection..
`Dim OrdLines As New Collection`
`OrdLines.Add (111,this is first item)`
`OrdLines.Add (222,this is second item)`
`OrdLines.Add (333,this is third item)`
`OrdLines.Add (444,this is fourth item)`
please guide me how to avoid duplicate values in collection
thanks in advance
推荐答案
创建循环并在循环中向集合添加数据。
然后检查是否收集包含值显示错误,
否则将数据添加到您的收藏中..
Create a loop and add data to your collection in the loop.
Then check if collection contains value show error,
Else add data to your collection..
For Each input As var In inputList
If OrdLines.Any(() => { }, str.Item1.Contains(firstinputvalue)) Then
' show error
Else
OrdLines.Add(input)
End If
Next
您可以检查ordlines是否包含您要添加的值
You could check if the ordlines contains the values you want to add
If OrdLines.Contains(555) Or OrdLines.Contains("This is the fifth item") Then
MessageBox.Show("One of these items allready excists")
Else
OrdLines.Add(555, "This is the fifth item")
End If
但是当您想要添加的值是5555时,您会有一个消息框
显示该值已经存在。
为了避免你可以使用等于并检查列表中的每个值
But when the value you want to add is 5555 then you would have a messagebox
showing that the value already excists.
To avoid that you could use an equals and check every value in your list
For Each item In OrdLines
If item.Equals(555) Then
MessageBox.Show("555")
ElseIf Not item.Equals(555) Then
OrdLines.Add(555, "This is the fifth item")
End If
Next
这篇关于如何避免vb6集合中的重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!