Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hello, am having difficulties moving the value of a variable from one form to another using windows application(desktop application).
could anyone please help?
am using vb.net
thanks
Posted
Comments
Sergey Alexandrovich Kryukov 27-Jun-12 21:00pm    
System.Windows.Forms? Add to the tags: "Forms". Do it; you are the most interested person to do it.
What does it mean: "moving the value" (learned COBOL before? :-)
What do you mean by "variable"? A class member or not?
--SA

I suppose you want to retrieve the value of variables in a form from another form, if that is the case then try this

Public Class Form1


Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim sure As Integer
Dim now As Integer
Dim yea As Integer

Form2.takeval(sure, now, yea)
End Sub
End Class

Now you can call it from form2 by.....

ublic Class Form2

Public Function takeval(ByVal num1 As Integer, ByVal num2 As Integer, num3 As Integer) As Integer
num1 = 5
num2 = 6
num3 = 7
Return num1 And num2 And num3
End Function

Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class

From that function in Form2 you can easily retrieve your values
 
Share this answer
 
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[^].

—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