By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,636 Members | 1,915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,636 IT Pros & Developers. It's quick & easy.

VB.NET: Transferring Data From Form to Form

P: n/a
Does anyone have any idea how to transferring data from TextBox1 in form1 to
textBox2 in form2.....

That means after i fill in any data in textBox1 and click Next button...

It will bring me to form2....and there the data that i key in form1 will
appear to form2 in textbox2
Thanks

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum
Nov 21 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
You must declare a Public variable, or else change the textbox declaration
to Public.

Then in form 2 you will be able to access the public members of Form1.

--
Gerry O'Brien [MVP]
Visual Basic .NET(VB.NET)


"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:%2***************@tk2msftngp13.phx.gbl...
Does anyone have any idea how to transferring data from TextBox1 in form1
to
textBox2 in form2.....

That means after i fill in any data in textBox1 and click Next button...

It will bring me to form2....and there the data that i key in form1 will
appear to form2 in textbox2
Thanks

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum

Nov 21 '05 #2

P: n/a
Hi,

This question from you, gives forever a lot of messages.
Very important is where you create your "other" form and how you do that.

(There are a lot of ways to do that in VBNet)

When that is known than it is a piece of cake to help you mostly.

Maybe you can show us that.

Cor
Nov 21 '05 #3

P: n/a
"Cor Ligthert" <no************@planet.nl> wrote in message news:<OK**************@TK2MSFTNGP10.phx.gbl>...
This question from you, gives forever a lot of messages.
Very important is where you create your "other" form and how you do that.


Regardless of where and how the "other" form is created, the best
method of passing data to a form for display is either by a property
or method of that form. The issue here is "How do I pass data to a
given form?"

In my opinion, public variables (that is global to the whole
application) should rarely be used. It is also my opinion that it is
not a good idea to make UI objects of a form public. It would be
better to create a form or a method for the form that is to accept the
data for display.

"Where" and "how" a form is created will simply determine where your
*reference* to that form is. However, that is a different issue. The
issue of when and where a form is created is "How do I reference a
form I've already created or am about to create?"
Nov 21 '05 #4

P: n/a
"Cor Ligthert" <no************@planet.nl> wrote in message news:<OK**************@TK2MSFTNGP10.phx.gbl>...
This question from you, gives forever a lot of messages.
Very important is where you create your "other" form and how you do that.


Regardless of where and how the "other" form is created, the best
method of passing data to a form for display is either by a property
or method of that form. The issue here is "How do I pass data to a
given form?"

In my opinion, public variables (that is global to the whole
application) should rarely be used. It is also my opinion that it is
not a good idea to make UI objects of a form public. It would be
better to create a form or a method for the form that is to accept the
data for display.

"Where" and "how" a form is created will simply determine where your
*reference* to that form is. However, that is a different issue. The
issue of when and where a form is created is "How do I reference a
form I've already created or am about to create?"
Nov 21 '05 #5

P: n/a

"DenBorg" <de******@yahoo.com> wrote
This question from you, gives forever a lot of messages.
Very important is where you create your "other" form and how you do that.


Regardless of where and how the "other" form is created, the best
method of passing data to a form for display is either by a property
or method of that form. The issue here is "How do I pass data to a
given form?"

I'll add my vote for either of those:

Dim OF As New OtherForm
' A method of the form
OF.SetData("Use this data" [, "Any other data"] )

Or;

' A property of the form
OF.RequiredData = "Use this data"
(methods are in order of preference)
LFS
Nov 21 '05 #6

P: n/a
DenBorg,

I never have a "best" method all is dependable from the situation.

I write forever here that in this the most advised method is using
properties.

When there were best methods the language would be very poor.

However the question was not what is the best, however "How" which means
that you should first get to the reference of the form before you can pass
anything. Will I show you the threads where people have trouble with that.
When there is no reference to the object, the property in that is
unreachable and you can not pass.

I hope this helps?

Cor
"DenBorg" <de******@yahoo.com>
Nov 21 '05 #7

P: n/a
> "Where" and "how" a form is created will simply determine where your
*reference* to that form is. However, that is a different issue. The
issue of when and where a form is created is "How do I reference a
form I've already created or am about to create?"


Yes therefore my question, from which you say that that is not needed.
This reference has more than one method depending on the is created form or
to create form.

I hope this helps?

Cor
Nov 21 '05 #8

P: n/a
> When there were best methods the language would be very poor.

I disagree. There are fundamental programming principles that are
universally applicable.

Let me give you one over-simplistic illustration. Suppose the
objective is to repeat a certain process several times. In my opinion,
the second of the following methods is clearly the best method:

'Method #1
DoSomething()
DoSomething()
DoSomething()
DoSomething()
DoSomething()
DoSomething()

'Method #2
Dim Index As Integer
For Index = 1 To 6
DoSomething()
Next 'Index

I am certain you would believe that the second method is clearly and
undoubtably better. But does that make Visual Basic a "very poor"
language just because Method #2 is better than Method #1? Of course
not.

By the same token, using Application Global variables is ill advised
in any programming language. And other means of transfering data from
one object to another is recommended and considered "better" than the
use of global variables.

Consider OOP programming verses linear programming. OOP was designed
to provide "better" methods of working with data and code. But instead
of making languages "very poor", these "better" designs makes these
languages "very good".

However the question was not what is the best, however "How" ...
Certainly you are not suggesting that when asked "How" we should offer
suggestions that are bad! Whenever someone asks me "How", I always try
to give them the best answer possible. And just because the person did
not explicitly ask for the "best", that does not mean that the person
wants "bad" answers.

However the question was not what is the best, however "How" which means
that you should first get to the reference of the form before you can pass
anything.
Yes, it is quite obvious that you must first have a reference to the
form before you can pass any information to it. However, having or
getting the form's reference has no bearing on how you should pass the
information to the form. They are two totally different issues.

Think about it this way. Suppose you create a form (named OtherForm)
at the same time you need to pass data to it. And let's say you create
a property named Data for the purpose of passing data to that form.
Your code would look something like the following:

Dim OF As New OtherForm

OF.Data = "data"

Now suppose that instead of creating OtherForm at the time you pass
data to it, you instead create OtherForm earlier on, and now need to
pass data to it. In other words, you need to data to a form that is
*already* opened.

My question to you is this: Should you change your method of passing
data to OtherForm simply because you changed when OtherForm is
created? Is using a property now a bad idea simply because OtherForm
is already loaded?

In other words, would you use one method of passing data (such as
global variables) to forms that were created at the start of the
program, but use a different method of passing data (such as
properties) to pass data to forms that are created immediately prior
to passing data to it?

My point is this: The method you use to pass data to a form is not
determined by when the form is created.
Will I show you the threads where people have trouble with that.
When there is no reference to the object, the property in that is
unreachable and you can not pass.


Again, this is blatantly obvious.

You don't have to know *when* the form is created, nor where the
form's reference is, before you can suggest methods of passing data to
the form.
Make sense?
-Dennis Borg
Nov 21 '05 #9

P: n/a
> When there were best methods the language would be very poor.

I disagree. There are fundamental programming principles that are
universally applicable.

Let me give you one over-simplistic illustration. Suppose the
objective is to repeat a certain process several times. In my opinion,
the second of the following methods is clearly the best method:

'Method #1
DoSomething()
DoSomething()
DoSomething()
DoSomething()
DoSomething()
DoSomething()

'Method #2
Dim Index As Integer
For Index = 1 To 6
DoSomething()
Next 'Index

I am certain you would believe that the second method is clearly and
undoubtably better. But does that make Visual Basic a "very poor"
language just because Method #2 is better than Method #1? Of course
not.

By the same token, using Application Global variables is ill advised
in any programming language. And other means of transfering data from
one object to another is recommended and considered "better" than the
use of global variables.

Consider OOP programming verses linear programming. OOP was designed
to provide "better" methods of working with data and code. But instead
of making languages "very poor", these "better" designs makes these
languages "very good".

However the question was not what is the best, however "How" ...
Certainly you are not suggesting that when asked "How" we should offer
suggestions that are bad! Whenever someone asks me "How", I always try
to give them the best answer possible. And just because the person did
not explicitly ask for the "best", that does not mean that the person
wants "bad" answers.

However the question was not what is the best, however "How" which means
that you should first get to the reference of the form before you can pass
anything.
Yes, it is quite obvious that you must first have a reference to the
form before you can pass any information to it. However, having or
getting the form's reference has no bearing on how you should pass the
information to the form. They are two totally different issues.

Think about it this way. Suppose you create a form (named OtherForm)
at the same time you need to pass data to it. And let's say you create
a property named Data for the purpose of passing data to that form.
Your code would look something like the following:

Dim OF As New OtherForm

OF.Data = "data"

Now suppose that instead of creating OtherForm at the time you pass
data to it, you instead create OtherForm earlier on, and now need to
pass data to it. In other words, you need to data to a form that is
*already* opened.

My question to you is this: Should you change your method of passing
data to OtherForm simply because you changed when OtherForm is
created? Is using a property now a bad idea simply because OtherForm
is already loaded?

In other words, would you use one method of passing data (such as
global variables) to forms that were created at the start of the
program, but use a different method of passing data (such as
properties) to pass data to forms that are created immediately prior
to passing data to it?

My point is this: The method you use to pass data to a form is not
determined by when the form is created.
Will I show you the threads where people have trouble with that.
When there is no reference to the object, the property in that is
unreachable and you can not pass.


Again, this is blatantly obvious.

But you don't have to know *when* the form is created, nor where the
form's reference is, before you can suggest methods of passing data to
the form.
Make sense?
-Dennis Borg
Nov 21 '05 #10

P: n/a
I hope this doesn't double post. I got an error message on my first
attempt, plus I think this post will be more concise and clearer.
When there were best methods the language would be very poor.
I disagree. There are fundamental programming principles that are
universally applicable.

Let me give you one over-simplistic illustration. Suppose the
objective is to repeat a certain process several times. In my opinion,
the second of the following methods is clearly the best method:

'Method #1
DoSomething()
DoSomething()
DoSomething()
DoSomething()
DoSomething()
DoSomething()

'Method #2
Dim Index As Integer
For Index = 1 To 6
DoSomething()
Next 'Index

I am certain you would agree that the second method is clearly and
undoubtably better. But does that make Visual Basic a "very poor"
language just because Method #2 is better than Method #1? Of course
not.

By the same token, using Application Global variables is ill advised
in any programming language. And other means of transfering data from
one object to another is recommended and considered "better" than the
use of global variables.

And consider OOP programming verses linear programming. OOP was
designed to provide "better" methods of working with data and code.
But instead of making languages "very poor", these "better" designs
makes these languages "very good".
However the question was not what is the best, however "How" ...
Whenever someone asks me "How", I always try to give them the best
answer possible. And just because the person did not explicitly ask
for the "best", that does not mean that the person wants "bad"
answers.

Again, the question was, and I am directly quoting the Original
Poster, "how to transferring data from TextBox1 in form1 to textBox2
in form2"

My point is that regardless of *when* Form2 is created, the "HOW TO"
of transferring data from Form1 to Form2 would be the same.
However the question was not what is the best, however "How" which means
that you should first get to the reference of the form before you can pass
anything.
Yes, it is quite obvious that you must first have a reference to the
form before you can pass any information to it. However, having or
getting the form's reference has no bearing on how you should pass the
information to the form. They are two totally different issues.

Think about it this way. Suppose you create a form (named OtherForm)
at the same time you need to pass data to it. And let's say you create
a property named Data for the purpose of passing data to that form.
Your code would look something like the following:

Dim OF As New OtherForm

OF.Data = "data"

Now suppose that instead of creating OtherForm at the time you pass
data to it, you instead create OtherForm earlier on, and now need to
pass data to it. In other words, you need to data to a form that is
*already* opened.

My question to you is this: Should you change your method of passing
data to OtherForm simply because you changed when OtherForm is
created? Is using a property now a bad idea simply because OtherForm
is already loaded?

My point is this: The method you use to pass data to a form is not
determined by when the form is created.
Will I show you the threads where people have trouble with that.
When there is no reference to the object, the property in that is
unreachable and you can not pass.


Again, this is blatantly obvious.

But you don't have to know *when* the form is created, nor where the
form's reference is, before you can suggest methods of passing data to
the form.
Make sense?
-Dennis Borg
Nov 21 '05 #11

P: n/a
"Cor Ligthert" <no************@planet.nl> wrote in message news:<ep**************@TK2MSFTNGP11.phx.gbl>...
"Where" and "how" a form is created will simply determine where your
*reference* to that form is. However, that is a different issue. The
issue of when and where a form is created is "How do I reference a
form I've already created or am about to create?"


Yes therefore my question, from which you say that that is not needed.
This reference has more than one method depending on the is created form or
to create form.


I never said that the reference is not needed to pass data from one
form to another.

What I was saying is that how you get your form reference has no
effect on the method of choice for transferring data to that form.

In other words, I am going to use a form property or method to
transfer data to a form regardless of whether that form is already
loaded or not.

If the form is loaded at the start of the application, I'll use a
property or method to transfer the data. And if I am loading the form
at the same time as passing the data, I'll still use that same
property.

My method of passing the data from one form to another will not be
affected by when that form was created. It does not matter if it was
created long ago. It does not matter if I am creating it now. It does
not matter how I get my form reference. Regardless, I am still going
to use that property or that method to transfer the data to that form.

Does that make sense?
Nov 21 '05 #12

P: n/a
"Gerry O'Brien [MVP]" <gerry dot obrien at gmail dot com> wrote in message news:<#f*************@TK2MSFTNGP12.phx.gbl>...
You must declare a Public variable, or else change the textbox declaration
to Public.


Gerry, I just thought I'd mention that I have not been trying to imply
that you were suggesting the use of an application global variable. As
far as I know, you may have meant a public variable of the form,
equivalent of a form property.
Nov 21 '05 #13

P: n/a
"Cor Ligthert" <no************@planet.nl> wrote in message news:<OK**************@TK2MSFTNGP10.phx.gbl>...
This question from you, gives forever a lot of messages.
Very important is where you create your "other" form and how you do that.


Cor, I understood you to be saying that the actual method of
transferring data to the other form would depend upon where that form
was created. Perhaps that is not what you were trying to say.

All I am saying is that regardless of how you obtain your form
reference, you would still transfer the data to the form in the same
way. If you were creating the form now, you would transfer the data
using the same method as you would if the form was created when the
application first started.

Hence my point: The how and when of when the form is created does not
affect the how of transferring the data to the form. You would use the
same method of transferring the data whether it's to an already loaded
form, or would to a form that is being loaded at this moment.
Nov 21 '05 #14

P: n/a
DenBorg,

Please see my other message

Cor
Nov 21 '05 #15

P: n/a
DenBorg,

I have not the idea that I have denied one word of what you wrote, except
that my addition in this thread is, that you first have to know where to get
the reference of the form.

That than the most advised method is for me obvious to use properties that
is for me not a part of a discussion. However a lot of people are in the
beginning still afraid of that, and than you start with a method that is
easier to learn, a kind of learning curve however mostly I write than that
better or advised is to use a property.

Cor
Nov 21 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.