Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help: Reference to a non-shared member requires an object reference Posted by Hamish_Noob on 7 May 2010 at 6:56 PM
Hi,
Im making a program in Visual Studio 2008 Express VB, and i get the following error on the code that follows:
ERROR:
Reference to a non-shared member requires an object reference.

  ''' <summary>
    ''' Shows or hides the status bar based on the menu command
    ''' </summary>
    Private Sub statusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ToolStripMenuItem.Checked = Not ToolStripMenuItem.Checked
        statusStrip1.Visible = ToolStripMenuItem.Checked
    End Sub


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

Report
Re: Help: Reference to a non-shared member requires an object... Posted by anthrax11 on 7 May 2010 at 10:08 PM
I think you want to be using statusBarToolStripMenuItem.Checked instead of ToolStripMenuItem.Checked.
Report
Re: Help: Reference to a non-shared member requires an object... Posted by Hamish_Noob on 8 May 2010 at 7:16 AM
What code should i actually use then, because when i use your changes, only 1 error is fixed
Report
Re: Help: Reference to a non-shared member requires an object... Posted by anthrax11 on 8 May 2010 at 12:26 PM
statusBarToolStripMenuItem.Checked = Not statusBarToolStripMenuItem.Checked
statusStrip1.Visible = statusBarToolStripMenuItem.Checked

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.
Report
Re: Help: Reference to a non-shared member requires an object... Posted by Hamish_Noob on 17 May 2010 at 1:06 AM
Ah, Thanks :D



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.