带有数字VB网络的文本框

时间:2018-10-26 04:13:45

标签: vb.net

我有以下代码。

 Var2txt.Text = Num1txt.Text + (" ") + Num2txt.Text + (" ") + Num6txt.Text + (" ") + Num7txt.Text + (" ") + Num9txt.Text
            Var3txt.Text = Num1txt.Text + (" ") + Num2txt.Text + (" ") + Num7txt.Text + (" ") + Num8txt.Text + (" ") + Num10txt.Text
            Var4txt.Text = Num1txt.Text + (" ") + Num3txt.Text + (" ") + Num4txt.Text + (" ") + Num5txt.Text + (" ") + Num7txt.Text
            Var5txt.Text = Num1txt.Text + (" ") + Num3txt.Text + (" ") + Num4txt.Text + (" ") + Num9txt.Text + (" ") + Num10txt.Text

我想展示以下方式。你认为可以吗?

N2 = 1 + (" ") + 2 + (" ") + 6 + (" ") + 7 + (" ") + 9
N3 = 1 + (" ") + 2 + (" ") + 6 + (" ") + 8 + (" ") + 10

以此类推。

我在代码中得到错误,索引超出了数组的边界。为什么会出现此错误?

        For i As Integer = 1 To TextBox2.Lines.Count
            If TextBox2.Lines(i).Contains(word) Then
                Dim tempTextBox As TextBox = CType(Me.Controls("CheckVar" & i.ToString), TextBox)
                If tempTextBox.Text.Contains(word) Then
                    MsgBox("")
                Else
                    tempTextBox.Text = tempTextBox.Text + " " + TxtbValAfterCompar.Text()
                End If
            End If
        Next
    Next

在此代码下,我没有收到此错误。当我尝试将其变暗以使其更短时,发生了错误。您可以看到代码了。

    If TextBox2.Lines(1).Contains(word) Then
        found = True
        If CheckVar1.Text.Contains(word) Then
        Else
            CheckVar1.Text = CheckVar1.Text + " " + TxtbValAfterCompar.Text()
        End If
    End If
    TxtbValBeforeCompar.Text = TextBox2.Lines(2)
    CompareNumbers()
    If TextBox2.Lines(2).Contains(word) Then
        found = True
        If CheckVar2.Text.Contains(word) Then
        Else
            CheckVar2.Text = CheckVar2.Text + " " + TxtbValAfterCompar.Text()
        End If
    End If

1 个答案:

答案 0 :(得分:0)

我不太确定您要完成什么以及为什么您需要这么多的文本框来表示类似的内容。我认为这可能是您要完成的工作?它将使用Textbox1,将其按行细分并逐个循环。如果该行的WordList中包含一个单词(1、2、3),则不会将其附加到输出文本框中。这样,您就可以创建单词的例外列表,并忽略TextBox1中的所有行。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim WordList As New List(Of String)(New String() {"one", "two", "three"})
    CompareTextBoxes(WordList)
End Sub

Private Sub CompareTextBoxes(WordList As List(Of String))
    For Each Line In TextBox1.Lines
        Dim LineList = Line.Split(" ").ToList()
        If WordList.Intersect(LineList).Count <= 0 Then
            TextBox2.Text += Line & vbCrLf
        End If
    Next
End Sub