【问题标题】:System.Indexoutofrangeexception in For StatementFor 语句中的 System.Indexoutofrange 异常
【发布时间】: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


【解决方案1】:

我修好了。 Textbox2 应该是 textbox1。我真的应该得到一个代码分析器。

【讨论】:

    猜你喜欢
    • 2018-04-24
    • 1970-01-01
    • 2014-01-25
    • 2014-05-20
    • 2011-11-29
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多