Hey Every1..
Plz Tell me how can i access The Value In form1 in form2...
Well i meant In Form1 theres an object named NUM in which i have Stored Few values Now i want to use this Object NUM in form2 so that i can display its value in Form2.. ima unable to access it in form2..
Can Any 1 tell me How to Access it ... Its an VB.net Project!

You can assign the Form1 value to a Form2 value by this:

Form 1

Private Class Form1
Private myCoolForm1Value As Integer = 6
End Class

Form 2, one Button

Private Class Form2
Private myCoolForm2Value As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myCoolForm2Value = Form1.myCoolForm1Value
MsgBox(myCoolForm2Value)
End Sub
End Class

See if this helps.

Oh, nice to remember Pgmer.
The variable needs to be public.

So, my correct code will be:

Private Class Form1
Public myCoolForm1Value As Integer = 6
End Class
Private Class Form2
Public myCoolForm2Value As Integer 'you only need to set this to public if you're going to use it later on another form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myCoolForm2Value = Form1.myCoolForm1Value
MsgBox(myCoolForm2Value)
End Sub
End Class

hi i have a similar problem.
i want the user to enter a value in a textbox in form1 and that value to be accessible in form2
this is my code
Form1

Public Class Form1

    Public var As Integer


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        var = TextBox1.Text


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()

    End Sub
End Class

and FORM2

Public Class Form2

    Public var2 As Integer

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

        var2 = Form1.var

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(var2)
    End Sub
End Class

Please tell me where i'm going wrong as the message box displays 0.

>>Please tell me where i'm going wrong as the message box displays 0.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        var = TextBox1.Text
        Form2.Show()
    End Sub

For future references @Kui, start you own thread for your "own" questions. Thanks.

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

      Form1.Textbox1.text = textbox1.text

    End Sub
This article has been dead for over six months. Start a new discussion instead.