我有以下代码。我想更改CheckVar并在一个文本框中执行此操作,仅用I修改该行。
If TextBox3.Lines.contains(i)(word) Then
Else
TextBox3.Lines.contains(i)= tempTextBox.Text + " " + TxtbValAfterCompar.Text()
我想使用textbox3.lines更改代码的外观。
这是下一个代码的显示方式。
For Each word In words
For i As Integer = 0 To TextBox2.Lines.Count - 1
TxtbValBeforeCompar.Text = TextBox1.Lines(i)
CompareNumbers()
If TextBox1.Lines(i).Contains(word) Then
found = True
Dim tempTextBox As TextBox = CType(Me.Controls("CheckVar" & i.ToString), TextBox)
On Error Resume Next
If TextBox2.Lines(i).Contains(word) Then
If tempTextBox.Text.Contains(word) Then
Else
tempTextBox.Text = tempTextBox.Text + " " + TxtbValAfterCompar.Text()
End If
Else
End If
End If
Next
Next
答案 0 :(得分:0)
我不确定您要用代码完成什么,但是我发表了一些评论可能会有所帮助。
Private Sub DoSomething()
Dim words() = {"Mathew", "Mark", "Luke", "John"}
Dim found As Boolean
For Each word In words
'How about checking if the number of lines in TextBox1 is
'equal to or more than the the number of lines in TextBox2.
'If it is less than the code will fail with an index out of range error
If TextBox1.Lines.Count < TextBox2.Lines.Count Then
MessageBox.Show("Sorry TextBox1 does not have enough lines.")
Exit Sub
End If
For i As Integer = 0 To TextBox2.Lines.Count - 1
TxtbValBeforeCompar.Text = TextBox1.Lines(i)
CompareNumbers()
If TextBox1.Lines(i).Contains(word) Then
found = True
'What is the point of tempTextBox? If is never visible and falls
'out of scope at the end of the Sub.
'Check that the number of CheckVars is not less than the number
'of lines in TextBox2
'REMEMBER The first value of i is 0 so you need a CheckVar0 TextBox
Dim counter As Integer
For Each ctrl As Control In Controls
If ctrl.Name.StartsWith("CheckVar") Then
counter += 1
End If
Next
'Of course you
If counter < TextBox2.Lines.Count Then
MessageBox.Show("Sorry, not enough CheckVarX controls.")
Exit Sub
End If
'What is the point of tempTextBox? If is never visible and falls
'out of scope at the end of the Sub.
Dim tempTextBox As TextBox = CType(Me.Controls("CheckVar" & i.ToString), TextBox)
'You could include the nested If in the outer If
'with AndAlso
If TextBox2.Lines(i).Contains(word) Then
'Use the Not keyword an get rid of the empty If
If Not tempTextBox.Text.Contains(word) Then
tempTextBox.Text = tempTextBox.Text + " " + TxtbValAfterCompar.Text()
End If
End If
End If
Next
Next
End Sub
Private Sub CompareNumbers()
'unknown code
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DoSomething()
End Sub