比较来自2个数组VB的数据

时间:2015-11-29 14:56:49

标签: arrays vb.net checkbox

我可以比较2个数组来检查Visual Basic中的活动复选框吗?有一个数组收集垂直列中的所有复选框,然后另一个数组收集水平列中的复选框。我对VB不是很好,所以请你为我简化答案。

    Dim Choice1(4) As Integer
    Choice1(0) = chkbocsYmg1Choice1.Checked
    Choice1(1) = chkbocsYmg2Choice1.Checked
    Choice1(2) = chkbocsYmg3Choice1.Checked
    Choice1(3) = chkbocsYmg4Choice1.Checked
    Choice1(4) = chkbocsYmg5Choice1.Checked

    Choice1(4) = "1"

这是垂直列

    Dim Line1(4) As Integer
    Line1(0) = chkbocsYmg1Choice1.Checked
    Line1(1) = chkbocsYmg1Choice2.Checked
    Line1(2) = chkbocsYmg1Choice3.Checked
    Line1(3) = chkbocsYmg1Choice4.Checked
    Line1(4) = chkbocsYmg1Choice5.Checked

这是水平列。 它是一个5x5网格的复选框,只有一个复选框在水平和垂直阵容中为真。

1 个答案:

答案 0 :(得分:0)

如果您以不同方式构建数组,则可以找到该值。这是下面的一个例子。不是我推荐这个,但我提供了一个示例,以便您可以看到填充的字符串数组

Public Shared Sub FindTheCheck()
    Dim checkbox1 As String
    Dim checkbox2 As String
    Dim checkbox3 As String
    Dim checkbox4 As String

    If TestingDataTable.CheckBox1.Checked = True Then
        checkbox1 = "CheckBox1 = 1"
    Else
        checkbox1 = "CheckBox1 = 0"
    End If

    If TestingDataTable.CheckBox2.Checked = True Then
        checkbox2 = "checkbox2 = 1"
    Else
        checkbox2 = "checkbox2 = 0"
    End If

    If TestingDataTable.CheckBox3.Checked = True Then
        checkbox3 = "checkbox3 = 1"
    Else
        checkbox3 = "checkbox3 = 0"
    End If

    If TestingDataTable.CheckBox3.Checked = True Then
        checkbox4 = "checkbox4 = 1"
    Else
        checkbox4 = "checkbox4 = 0"
    End If

    Dim array1 = New List(Of String)

    array1.Add(checkbox1)
    array1.Add(checkbox2)

    Dim array2 = New List(Of String)

    array2.Add(checkbox3)
    array2.Add(checkbox4)


    Dim found As String

    For Each checkstate1 In array1

        If checkstate1.Contains("1") Then

            found = checkstate1

        End If

    Next

    For Each checkstate2 In array2

        If checkstate2.Contains("1") Then

            found = checkstate2

        End If

    Next