473,545 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to reference form field...

I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
Jun 27 '08 #1
9 2889
On Jun 3, 6:52*pm, "Brad Pears" <br...@truenort hloghomes.comwr ote:
I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
Without seeing your full code, i found that suggestion which may work
for you:
http://www.velocityreviews.com/forum...ed-member.html

Thanks,

Onur Güzel
Jun 27 '08 #2
Unfortunately that solution appears to be specific to ASP... I will jsut use
a public variable for now but I'd like to get to the bottom of that issue...

Thanks for the response...

Brad

"kimiraikko nen" <ki************ *@gmail.comwrot e in message
news:55******** *************** ***********@p25 g2000hsf.google groups.com...
On Jun 3, 6:52 pm, "Brad Pears" <br...@truenort hloghomes.comwr ote:
I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
Without seeing your full code, i found that suggestion which may work
for you:
http://www.velocityreviews.com/forum...ed-member.html

Thanks,

Onur Güzel
Jun 27 '08 #3
On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenort hloghomes.comwr ote:
>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.
Jun 27 '08 #4
Ok, that sounds good. I will implement it like that instead. In teh meantime
I decided to use a public variable (pJobNo) which works fine, but I prefer
not to use them if there is a better method that is not too difficult of an
implementation.

Thanks, Brad

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:n4******** *************** *********@4ax.c om...
On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenort hloghomes.comwr ote:
>>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad

If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.

Jun 27 '08 #5
One other quick question...

When you said

" Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number."

I'm just not sure what you mean there...

Basically I want to call your function "GetJobNo" in a completely different
form (the one that calls the stored procedure) than the one that fucntion
"GetJobNo" was declared public in. I can't do that unless I pass the actual
entire form by reference to the new form - is that what you mean?

Could you give me a quick example of what you are referring to there?

Thanks, Brad

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:n4******** *************** *********@4ax.c om...
On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenort hloghomes.comwr ote:
>>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad

If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.

Jun 27 '08 #6
Yes. You need a reference to the form that contains the textbox
(saying "pass the actual entire form by reference" doesn't really mean
anything, a reference is a pointer to the instantiation of the class).

You can get the reference in a couple of ways. If the form with the
textbox starts the other form, then it is easy. If the second form is
a modal dialog box then you will have code like:

Using frm2 As New Form2
frm2.ShowDialog ()
End Using

To pass a reference to the calling form you can either pass it as a
parameter to the form's New or call a method:

Using frm2 As New Form2(Me)
or
Using frm2 As New Form2
frm2.SetCalling Form(Me)
frm2.ShowDialog ()
End Using

You could also look through the application's list of forms to find
the form you want (System.Windows .Forms.Applicat ion.OpenForms).

On Tue, 3 Jun 2008 17:01:49 -0400, "Brad Pears"
<br***@truenort hloghomes.comwr ote:
>One other quick question...

When you said

" Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number."

I'm just not sure what you mean there...

Basically I want to call your function "GetJobNo" in a completely different
form (the one that calls the stored procedure) than the one that fucntion
"GetJobNo" was declared public in. I can't do that unless I pass the actual
entire form by reference to the new form - is that what you mean?

Could you give me a quick example of what you are referring to there?

Thanks, Brad

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:n4******* *************** **********@4ax. com...
>On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@truenor thloghomes.comw rote:
>>>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad

If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.
Jun 27 '08 #7
Brad,

A class is only a template, this is a little bit confusing for former VB6
users, as in that language where AFAIK classes always shared classes, and
therefore in fact modules.

The form class is now a real class. And therefore you have to instance it
from your current class to an obect.

Therefore as you show us how you have instanced frmSteelPlates, then some of
us can tell you probably more.

(There are and endles quantity of methods to create an form object)

Cor

"Brad Pears" <br***@truenort hloghomes.comsc hreef in bericht
news:eB******** ******@TK2MSFTN GP06.phx.gbl...
>I have the following code that references a "textbox" on a form. I want to
pass the value of this textbox to a stored procedure as a parameter. This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the
value of the text box actually is...

"Reference to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
Jun 27 '08 #8
On Wed, 4 Jun 2008 05:40:36 +0200, "Cor Ligthert[MVP]"
<no************ @planet.nlwrote :
>Brad,
Cor,
>A class is only a template, this is a little bit confusing for former VB6
users, as in that language where AFAIK classes always shared classes, and
therefore in fact modules.
In VB6, a class must be stored in a single file and a single file
cannot contain more than one class. Still, except for the lack
of inheritance, classes in VB6 work pretty much like those in
VB.Net, albeit a little crippled by comparison.

A default instance of a form in VB6 can be referenced without
instantiation, but it is also possible to create multiple, non-default
instances of a form.
>The form class is now a real class. And therefore you have to instance it
from your current class to an obect.
This was true in VS2002 and VS2003, but VS2005 (re)introduced
the default instance model known from VB6, so in VB.Net 2005+ it
is now possible to write

Sub main()
Form1.ShowDialo g()
End Sub

i.e. display the default instance of a form without declaring
it first. This is (now) handled behind the scenes.

If all you ever need is to display one instance of the same
form class at a time, the default instance can be used.

My personal opinion is that Microsoft never should have
added the default instance stuff but kept forcing developers
to keep things explicit, i.e. out in plain view. Less opportunity
for errors and confusion.
>Therefore as you show us how you have instanced frmSteelPlates, then some of
us can tell you probably more.
I'll second that.

Regards,

Joergen Bech

Jun 27 '08 #9
Got it!!

I'm pretty new to this stuff...

Thanks, Brad

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:ep******** *************** *********@4ax.c om...
Yes. You need a reference to the form that contains the textbox
(saying "pass the actual entire form by reference" doesn't really mean
anything, a reference is a pointer to the instantiation of the class).

You can get the reference in a couple of ways. If the form with the
textbox starts the other form, then it is easy. If the second form is
a modal dialog box then you will have code like:

Using frm2 As New Form2
frm2.ShowDialog ()
End Using

To pass a reference to the calling form you can either pass it as a
parameter to the form's New or call a method:

Using frm2 As New Form2(Me)
or
Using frm2 As New Form2
frm2.SetCalling Form(Me)
frm2.ShowDialog ()
End Using

You could also look through the application's list of forms to find
the form you want (System.Windows .Forms.Applicat ion.OpenForms).

On Tue, 3 Jun 2008 17:01:49 -0400, "Brad Pears"
<br***@truenort hloghomes.comwr ote:
>>One other quick question...

When you said

" Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number."

I'm just not sure what you mean there...

Basically I want to call your function "GetJobNo" in a completely
different
form (the one that calls the stored procedure) than the one that fucntion
"GetJobNo" was declared public in. I can't do that unless I pass the
actual
entire form by reference to the new form - is that what you mean?

Could you give me a quick example of what you are referring to there?

Thanks, Brad

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:n4****** *************** ***********@4ax .com...
>>On Tue, 3 Jun 2008 11:52:20 -0400, "Brad Pears"
<br***@trueno rthloghomes.com wrote:

I have the following code that references a "textbox" on a form. I want
to
pass the value of this textbox to a stored procedure as a parameter.
This
code is located on a different form obviously. I thought that I would be
able to reference the textbox simply by placing the name of the form it
is
located on (class name) in front as follows...

param1 = frmSteelPlates. txtJobNo.Text

I am getting the following error when I debug the line to see what the
value
of the text box actually is...

"Referenc e to a non-shared member requires an object reference"

What am I missing here?

Thanks, Brad
If frmSteelPlates is a reference to the other form, and if txtJobNo is
marked Public, then it would work.

My guess is that frmSteelPlates is a class name, not a reference to an
instance of the class.

I don't think it is good practice to make controls be Public and
reference them from somewhere else. It ties the code too closely to
how you chose to implement the form.

I would add to the form that contains the textbox a Public Function
that returns the value, something like:

Public Function GetJobNo() As String
Return txtJobNo.Text
End Function

Then arrange for the form that calls the stored procedure to have a
reference to the form that has the job number.

Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2356
by: Terje Sæternes | last post by:
It seems that this script wont run, any idea what I have don wrong+ Code----- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="javascript" type="text/javascript"> <!--
5
1866
by: Rose | last post by:
I want to use the javascript dom to reference the field of a record in a multi-record html form when that field has been changed. How do I reference the field? I have a JavaScript function coded as: var zownerID = document.updOwners.ownerID.value var zownerName = document.updOwners.ownerName.value document.updOwners.mysql_update.value =...
1
2213
by: ubmc | last post by:
Revised form layout by dragging/dropping fields from field list and deleting unwanted fields. However, unable to go to next existing record or return to previous existing record, but can add new record. Error message received when attempting to go to next or previous existing record: "The value you entered isn't valid for this field."
3
1731
by: hmiller | last post by:
I have created and IIF statement in an unbound text box. The IIF statement produces a text result, ie "On Time", in the unbound text box. What I would like to do is reffence this text box and then the result contained in the text box. Something like this: =Dcount("*","The form where the unbound text box is","TextBox='On Time'") How can I...
1
4224
by: hrhoe | last post by:
Hi, I'm trying to create a reusable component with C#. So, I created a user control that uses Microsoft SQLDMO Object Library (SQLDMO). And I could add that UserControl on Toolbox. However, whenever I'm trying to add this user control on the client program's form I'm getting the following error message. ----------------------
14
17998
by: mchlle | last post by:
How can I filter records of a subform that is part of a tab control? The filter works fine on the form when it is not part of the tab using this in the macro condition: !!="Today" I have a main form with a tab control which has three tabs and on each tab there is a subform. Main Form: frmEmploymentVerification Tab Control Name:...
7
10606
by: planetthoughtful | last post by:
Hi All, I have an app that presents a small main form when run. When a particular button is clicked, I'd like to briefly display another small form directly below the main form, regardless of where on the screen the main form is currently located. I'm trying to work out how, from the class that displays the second form, I reference the x...
2
2605
by: Kanashii | last post by:
First off - I want to thank all who respond / try to help out and even those who took a moment to read over my question. Please be patient as I am -very- new to VB in general and unfortunately I've only had the chance to pick up pieces here-and-there. So keep that in mind when reading my inquiry as I am liable to misuse terminology. My...
0
2657
by: ll | last post by:
I'm working with 'pure ASP upload' script which is designed to redirect to an alert/error message, should a file larger than the set limit be attempted to be uploaded. The problem is that, while smaller files do upload successfully, the script does not catch the larger files and rather than a specific error message in Firefox (and IE7), I...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7918
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7436
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7766
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5981
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
1897
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
715
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.