Question transfer data

phaeight

New member
Joined
Jul 11, 2011
Messages
3
Programming Experience
Beginner
hello,
i would like some help for me to transfer the value of sum in form 1 to form 2.
here is my code:


Public Class Form1 Dim secondform As New Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim num1, num2, sum As Integer num1 = TextBox1.Text num2 = TextBox2.Text sum = num1 + num2 secondform.Show() End Sub End Class<br/>



i need answer ASAP, please......
 
First, please format your code properly, do a quick search on how to format codes properly on this form. Ex: using
HTML:
[XCODE=vb][/XCODE] or [CODE][/CODE]

passing values is simple, simply make the variable Public/Friend/Protected Friend and you should be able to access it like Form2.Variable and then get/set the value.

EX:
on your form you want to pass the variable to
Public Class Form2
    Public message As String = ""

    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label1.Text = message
    End Sub
End Class

then wherever you are using the form say in a button click in another forum for example:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm2 As New Form2

        frm2.message = "Hello World"
        frm2.Show()
    End Sub
End Class
 
thanks reminding me about the code formatting....
the code you give work and i understand it clearly now....
thanks very much...
 
Back
Top