VB 2010 Microsoft.VisualBasic.dll中出现类型为“System.InvalidCastException”的第一次机会异常

时间:2013-10-27 18:35:38

标签: vb.net visual-studio-2010 visual-studio visual-studio-2012

我是Visual Basic 2010编程的新手。 我有这些错误:

  

“System.InvalidCastException”类型的第一次机会异常   发生在Microsoft.VisualBasic.dll

这是我的代码。

Public Class Form1

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If TextBox2.ReadOnly = True Then
        TextBox2.ReadOnly = False
    End If
End Sub

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If TextBox3.ReadOnly = False Then
        TextBox3.ReadOnly = True
        TextBox3.Text = "|n/a|"
    End If
    If TextBox2.ReadOnly = False Then
        TextBox2.ReadOnly = True
    End If
End Sub

  Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
    TextBox3.Text = "[1.5.2]"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If CheckBox1.Checked Then
        Button1.Enabled = False
        Threading.Thread.Sleep(500)
        Button2.PerformClick()
        Button3.PerformClick()
        Button4.PerformClick()
        Threading.Thread.Sleep(500)
        If RichTextBox1.Text = Nothing Then
            Threading.Thread.Sleep(5000)
            Button3.PerformClick()
            Button3.PerformClick()
            Label4.Text = "Next try in 10 seconds"
            Threading.Thread.Sleep(10000)
            Label4.Text = "Trying...."
            Button1.Enabled = True
            Button1.PerformClick()
        End If
    End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    TabControl1.SelectedTab = TabPage2
    Threading.Thread.Sleep(1000)
    WebBrowser2.Navigate("https://login.minecraft.net?user=" + TextBox1.Text + "&password=" + TextBox2.Text + "&version=13")

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    RichTextBox1.Text = WebBrowser2.DocumentText
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    If WebBrowser2.DocumentText.Contains("Bad login") Then
        MessageBox.Show("Bad login!")
    End If
    If WebBrowser2.DocumentText.Contains("User not premium") Then
        MessageBox.Show("User not premium! Please buy Minecraft at the http://minecraft.net/ ")
    End If
    If RichTextBox1.Text.Contains("Bad login") Then
        MessageBox.Show("Bad login!")
    End If
    If RichTextBox1.Text.Contains("User not premium") Then
        MessageBox.Show("User not premium! Please buy Minecraft at the http://minecraft.net/ ")
    End If
End Sub

End Class

1 个答案:

答案 0 :(得分:1)

InvalidCastException意味着您尝试将对象视为其他对象,而不是它。例如,您不能将字符串视为整数。我认为它与TabPage2有关。我没有看到任何声明。