locked
Sending data between forms RRS feed

  • Question

  • Visual Basic 2005 Express:

    Dim f2 As Form2 = New Form2()

    Form2.ShowMaxOrMan() = "Max"
    ' Form2 gets "Max" OK
    f2.ShowDialog()
    ' But, when Form2_Load routine runs, MaxOrMan gets initialized, losing the data that Form1 sent! 

     

    Tuesday, July 11, 2006 6:01 AM

Answers

  • This may not be the best way but .....

    Public Class Form1

    Public str As String

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

    str = "hey"

    My.Forms.Form2.ShowDialog()

    End Sub

    End Class

    Public Class Form2

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

    MsgBox(My.Forms.Form1.str)

    End Sub

    End Class

    Tuesday, July 11, 2006 7:00 AM

All replies

  • This may not be the best way but .....

    Public Class Form1

    Public str As String

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

    str = "hey"

    My.Forms.Form2.ShowDialog()

    End Sub

    End Class

    Public Class Form2

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

    MsgBox(My.Forms.Form1.str)

    End Sub

    End Class

    Tuesday, July 11, 2006 7:00 AM
  • Short 2nd answer.

    I don't think you need the

    Dim f2 As Form2 = New Form2()

    line at all.

    Tuesday, July 11, 2006 7:08 AM
  • I am tired tonight.

    The correct answer is

    change

    Form2.ShowMaxOrMan() = "Max"

    to

    F2.ShowMaxOrMan() = "Max"

    Tuesday, July 11, 2006 7:19 AM
  • #1 worked!

    Thanks!!!!

     

    Tuesday, July 11, 2006 2:29 PM
  • you can edit the values of a form from another by using



    system.io.form2.label1.text="ha!"



    Sunday, July 16, 2006 8:56 PM