简体   繁体   中英

VB Evaluate two integers with a list

I want to evaluate two integers separated with values of list of two integers.

在此处输入图片说明

For example:

i receive two integers from two variables

id1 = 1

id2 = 2

Then i have a list of two integers

1 - 2

4 - 6

I want to check if that ids are in the list of integers together. Since we cannot do

For e = 0 To excluidos.Count
    If misGallos(i).taquillaP = excluidos(e).id1P Or excluidos(e).id2P And _
       misGallos(j).taquillaP = excluidos(e).id1P Or excluidos(e).id2P Then

        MsgBox("igua")
    End If
Next e

I dont know whats the better way to do it. If i should put those ids in another list to compare both list or if exist any method to put those ids together and check if there are equals on the list.

That's because your logic is wrong, try something like this:

    Dim List1 As New List(Of Integer) From {1, 3, 5, 22}
    Dim List2 As New List(Of Integer) From {2, 4, 8, 12}
    Dim ID1 As Integer = 22
    Dim ID2 As Integer = 12

    If List1.Contains(ID1) Then

        If List2.Contains(ID2) AndAlso List2(List1.IndexOf(ID1)) = ID2 Then 'is present on list and same row
            Debug.Print("hi1")
        End If

    ElseIf List2.Contains(ID1) Then

        If List1.Contains(ID2) AndAlso List1(List2.IndexOf(ID1)) = ID2 Then 'is present on list and same row
            Debug.Print("hi2")
        End If

    End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM