#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Location
    Somewhere in the vicinity of Betelgeuse
    Posts
    121
    Rep Power
    9

    Handled Runtime Exception not sure how to fix it.


    I think I've narrowed down where the exception is actually coming from:

    VB Code:
        Private Sub cmbDBType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbDBType.SelectedIndexChanged
            Dim DBType As String
            DBType = cmbDBType.SelectedItem.ToString
            Select Case DBType
                Case "MSSQL"
                    txtDBPort.Text = "1443"
                Case "MySQL"
                    txtDBPort.Text = "3306"
                Case "PostgreSQL"
                    txtDBPort.Text = "5432"
            End Select
            If cmbDBType.SelectedItem Is "MSSQL" Or cmbDBType.SelectedItem Is "PostgreSQL" Then
                MessageBox.Show("Feature not yet implemented", "Option Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        End Sub


    When I run the program, it throws this exception:

    Code:
    A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
    I've looked through other forums and I turned on Option Strict and had to make some changes, namely the Is statements. Others in those other forums say to tell the compiler not to show those warnings. I'm using Visual Studio 2012 and .NET 4. Is my code good and VB is being picky, or can I improve this code so it doesn't throw the error? If so, how? I haven't messed with VB in quite some time so I'm a bit rusty with it.

    I fiddled around with it for a while and then got frustrated and saved and closed VS2012. When I opened it back up I didn't get the error anymore. Must've not cleared it when it was fixed.
    Last edited by winblowzxp; June 12th, 2013 at 12:15 PM. Reason: Solution found

IMN logo majestic logo threadwatch logo seochat tools logo