Help: Reference to a non-shared member requires an object reference

Hi,
Im making a program in Visual Studio 2008 Express VB, and i get the following error on the code that follows:
ERROR:
[code]Reference to a non-shared member requires an object reference.
[/code]
[code] '''
''' Shows or hides the status bar based on the menu command
'''
Private Sub statusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
ToolStripMenuItem.Checked = Not ToolStripMenuItem.Checked
statusStrip1.Visible = ToolStripMenuItem.Checked
End Sub[/code]

The 2 lines that get this error are:
[code]
ToolStripMenuItem.Checked = Not ToolStripMenuItem.Checked
statusStrip1.Visible = ToolStripMenuItem.Checked[/code]

Comments

  • I think you want to be using statusBarToolStripMenuItem.Checked instead of ToolStripMenuItem.Checked.
  • What code should i actually use then, because when i use your changes, only 1 error is fixed
  • [code]statusBarToolStripMenuItem.Checked = Not statusBarToolStripMenuItem.Checked
    statusStrip1.Visible = statusBarToolStripMenuItem.Checked
    [/code]
    ToolStripMenuItem.Checked doesn't mean anything by itself. The class has the Checked property, but you can only use properties of an instance of the class, not the class itself.

    There may be several instances of a class, that's why instances have a name that is similar to, but different from the class name. You might have the instances statusBarToolStripMenuItem1 and statusBarToolStripMenuItem2. When using one of these instances, you would refer to it by its instance name, not the class name, which is ToolStripMenuItem. That way it is understandable, which instance you are using.
  • Ah, Thanks :D
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories