Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to send a variables between the forms
please send answers
Posted
Comments
Maciej Los 7-Aug-13 15:32pm    
Why? What do you want to achieve?
Winston Madiano 7-Aug-13 20:32pm    
Let me google that for you
see the ff. link
http://lmgtfy.com/?q=vb.net+sending+values+between+forms

Passing a variable from form1 to form2

In Form 2 first declare the Varible.....

VB
public var1 as string

Then in form1....

VB
Dim f as new form2
f.var1 = "Testing"
f.show

in the load event of form2 put the following code:
VB
messagebox.show var1

It looks like you are still learning.... Before you Google for the answer, Google for "Visual Basic For Beginners" :)
 
Share this answer
 
v3
Comments
Maciej Los 7-Aug-13 15:44pm    
Wrong! See my answer.
Member 10195652 12-Sep-13 11:03am    
its have a error
show method does not declare
Is Google really broken [^]at your place?

A simple search has given me about 1,530,000 results in (0.27 seconds).

Anyway, look at the following link on CP. Should help:

Pass value between two form in vb.net[^]
 
Share this answer
 
I'm not sure what do you want to achieve (see my comment to the question), but it's a basic knowledge about ...
Scope in Visual Basic[^]
Variable and Method Scope in Microsoft .NET[^]

If yout want to know how to pass data between forms, use SearchBox[^]. There is tons of information about it.
 
Share this answer
 
Comments
Tiaan Lombard (TiLO) 7-Aug-13 16:41pm    
Poor you.... In .NET unlike VB6 a form is actually a class that can accept any function, variable property etc just as any other class :(
Maciej Los 7-Aug-13 16:55pm    
Tiaan, the code you provided is really bad, because of several reasons. Let imagine, i have 10 forms and i would like to share some data between them. Are you trying to tell me that i need to define 10 variables, one for each form? No, it's bad practice! Come back here when you'll be ready to discuss and you'll find an arguments to discuss, but first read linked articles...
This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900