【发布时间】:2014-07-15 03:21:00
【问题描述】:
我正在编写一个解析器并且发生了这个异常。这是代码
Private Sub BackgroundWorker1_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For i As Integer = 0 To TextBox1.Lines.Length - 1
If TextBox2.Lines(i).StartsWith("print") = True Then
Dim str1 As String = TextBox2.Lines(i).ToString.Replace("print", "echo")
TextBox2.Text = TextBox2.Text + Environment.NewLine + str1
ElseIf TextBox2.Lines(i) = "selfping" Then
TextBox2.Text = TextBox2.Text + Environment.NewLine + "ping 127.0.0.1"
ElseIf TextBox2.Lines(i) = "pause empty" Then
TextBox2.Text = TextBox2.Text + Environment.NewLine + "pause >nul"
ElseIf TextBox2.Lines(i) = "clear" Then
TextBox2.Text = TextBox2.Text + Environment.NewLine + "cls"
Else
TextBox2.Text = TextBox2.Text + Environment.NewLine + TextBox2.Lines(i)
End If
Next
End Sub
这适用于每一个 If 和 ElseIf 语句。
【问题讨论】:
-
TextBox2.Lines(i)- 看起来像一个数组 -
是的,不幸的是我没有经验,我不知道什么是数组。
-
TextBox1是多行文本框吗? -
您正在检查 TextBox1 中的行数,然后遍历 TextBox2 的行集合,您怎么知道 TextBox2 中的行数实际上与 TextBox1 中的行数相同?
-
这是因为TextBox1中的每一行代表了textbox2中的每一行。我是这样编码的。
标签: vb.net visual-studio exception