473,480 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

passing variable between forms

Hello there
I know that if I have more than one form in the same project I will have to
create variables of any form I need to use.
I manage to open forms using the show(), now what I need to do is to set the
value of a control's property on the calling form.
As I can do that from the calling form to any control on the instance of
form2, how do I do the contrary?
Example:
I have form1, it contains a text box and a button.
I click on the button and an instance of form2 shows up.
I have a button on form2, I click on this button, and the text property of
the text box on form1 changes.
Any ideas on how do I do that?
Nov 20 '05 #1
5 1215
on form2 button event
form1.texbox1.text=( i don't know what inside buuton on form2)

regards,

Sameh Ahmed wrote:
Hello there
I know that if I have more than one form in the same project I will have to
create variables of any form I need to use.
I manage to open forms using the show(), now what I need to do is to set the
value of a control's property on the calling form.
As I can do that from the calling form to any control on the instance of
form2, how do I do the contrary?
Example:
I have form1, it contains a text box and a button.
I click on the button and an instance of form2 shows up.
I have a button on form2, I click on this button, and the text property of
the text box on form1 changes.
Any ideas on how do I do that?


Nov 20 '05 #2
Dear Supra and John
I know what you mean, and i have to declare a variable of form1 type.
But this would be appropriate if i am calling a new instance of form1. which
is not the case.
as fom1 is the caller for form2 and i need to modify a control on the
existing form1.

* when i added
form1.textbox1.text = "test"
the error "Reference to a non-shared member requires an object reference."
was generated.

* When I added
Dim frn As Form1
frn.textbox1.text = "test"
the runtime error "Object reference not set to an instance of an object."
was generated

* As for using
Dim frn As new Form1
frn.textbox1.text = "test"
nothing happens and when i show frm the control property is modified
nnormally, but again i want to modiy a property in the calling form not in a
freshly called instance.

thanks again and hope somebody can help.
Regards
Sameh
"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
Yes...it's kind of like a file path. Just precede the controlname (button1) with the form name(form1). Such as: "form1.button1.text = "OK""
You will also need to declare form1 on form2 if you reference it. Put a statement such as: "Dim frm1 as New Form1" on form2.
John

Nov 20 '05 #3
I'm just learning .Net also and I know it sounds wrong but you NEED to declare form1 on form2 with a statement like

dim frm1 as new Form

then reference it as frm1. Even though it already exists

John
Nov 20 '05 #4
ISK
the idea is right.

here's what you can do.

'This is code in form1 for some button1 which is loading your form2 - note the Init metho
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clic
Dim ofrm As New Form
ofrm.Init(Me
ofrm.Show(
End Su

'This is code in form2 - the Init method takes in a reference to type form1 - this will give you the handle to your calling for
Private m_oCallingForm As Form

Friend Sub Init(ByRef oCallingForm As Form1
m_oCallingForm = oCallingFor
End Su

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clic
m_oCallingForm.Button1.Text = "Changed
End Su

hope this helps.

----- jcrouse wrote: ----

I'm just learning .Net also and I know it sounds wrong but you NEED to declare form1 on form2 with a statement like

dim frm1 as new Form

then reference it as frm1. Even though it already exists

John
Nov 20 '05 #5
Did not work
as this is not the instance that needs to be modified
Regards
Sameh
"jcrouse" <an*******@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
I'm just learning .Net also and I know it sounds wrong but you NEED to declare form1 on form2 with a statement like:
dim frm1 as new Form1

then reference it as frm1. Even though it already exists.

John

Nov 20 '05 #6

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

Similar topics

7
6387
by: rickcheney | last post by:
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was...
9
2139
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script...
2
4011
by: Matthew Clement | last post by:
I'm currently building a form (called frmReports) to set the criteria for a query, but I'm having some trouble with syntax and hope that one of the guru's here can help me achieve what I'm do. ...
3
5521
by: SV | last post by:
Dear all, In my application I have a lot of hidden fields. I want to make them invisible for the users though for debugging reasons I want to make them visible. So I want to add these objects to...
1
2915
by: sofakingfree | last post by:
I keep getting an invalid property assignment error when tring to reference a subform. All I am trying to do is substitute this: Forms!!.SetFocus for this: FormAndSubForm.SetFocus
11
3455
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
8
4393
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
6
3239
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
13
2456
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
1
1800
by: rfr | last post by:
I have a need to use a single version of a Visitor Response Feedback Form on numerous HTML documents. Rather than have numerous versions of this, one on each HTML document, it makes more sense to...
0
7033
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7027
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,...
0
7071
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...
1
6726
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...
0
5318
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,...
0
4468
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1291
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 ...
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.