Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
|
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2010, 10:52 PM
Authorized User
 
Join Date: Aug 2010
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default What is "Reference to a non-shared member requires an object reference"?

Hello,I met a strange problem here.
I use VB2008 to new a ClassLibrary project(to build a dll),then add two Windows Forms(Form1 and Form2) to the project.Add a TextBox1 to Form1.Then,When I type "Form1.TextBox1.Text" in Form2's Code editor,an error occur,it's "Reference to a non-shared member requires an object reference".There is no such problen in VB6.0,I never meet it before.
 
Old November 14th, 2010, 01:08 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

It means your Form1 is, apparently, the name of your CLASS. Unless the field TestBox1 is a SHARED member of that class, you must first create and *OBJECT* of the Form1 type and then reference the member via that.

In other words, your code looks something like this:
Code:
Class Form1
    Public Textbox1 AS TextBox
    ...
 
... then some place in your other code:
 
    Public Sub someMethod( )
        Form1.Textbox1.Text = "abc"
...
You would need to do
Code:
    Dim myForm As New Form1
    ...
    myForm.Textbox1.Text = "abc"
If you don't create the Form1 object by using
Code:
    New Form1
then the form will not be "instantiated" and so nothing can appear on the screen.
 
Old November 14th, 2010, 09:48 PM
Authorized User
 
Join Date: Aug 2010
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you very much.I will try it as what you said.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulties with "web.config" and "ASPNETDB" CFRham BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 2 July 3rd, 2010 10:19 AM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Response.Redirect gets "object required" error Ron Howerton VBScript 2 August 27th, 2009 01:45 PM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.