Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

Getting the proverbial "Object reference not set to an instance of an object" error?

I've created a class that inherits the System.Windows.Forms.TabPage class. I'm not sure how to declare an instance of the class. There needs to be an instance for each TabPage created on a specific TabControl. I basically set this new property in the "SelectedIndexChanged()" Event. I'm getting Object Reference error because I'm not sure how to declare the variable.

New Class
Public Class tabPageViewed
    Inherits System.Windows.Forms.TabPage

    Private _viewed As Boolean

    Property TabViewed() As Boolean
        Get
            TabViewed = _viewed
        End Get
        Set(value As Boolean)
            _viewed = value
        End Set
    End Property

End Class

Open in new window



What is the difference in the two statements below?

'Statement 1
     Private tabV() As tabPageViewed

'Statement 2
     Private tabV As New tabPageViewed()

Open in new window


How should it be declare with regard to the context in which I'm using it. I only set and check this property in the "SelectedIndexChanged()" Event.

Thanks!
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

Here is how I'm using the class

    Private Sub tabChannelTestLoad_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tabChannelTestLoad.SelectedIndexChanged
        Try
            EH.ErrorMessage = String.Empty

            idx = tabChannelTestLoad.SelectedIndex

            If tabChannelTestLoad.SelectedIndex <> -1 And Not clsTabViewed.TabViewed Then
                clsTabViewed.TabViewed = True

                Perform various functions...

            End If

ProcessMessage:

        Catch ex As Exception
            EH.ErrorMessage = "frmCalibration_3/tabChannelTestLoad_SelectedIndexChanged() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How should I declare it with reference to how I'm using it?

See post 40881158!
Thanks!