Results 1 to 2 of 2

Thread: Passing txt.Text to another form

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    106

    Passing txt.Text to another form

    I can't seem to pass values from Form1 to Form2 when i click
    btnSubmit_click.

    Form1:

    txtName
    txtAge

    Form2:

    Dim Form2 As New frmMain2()

    strName = Form2.txtName.Text
    strAge = Form2.txtAge.Text

    lblName.Text = strName <- doesnt show!

  2. #2
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Passing txt.Text to another form

    txtName and txtAge in Form2 will be empty (unless otherwise defined at design time) because you have only just created an instance of the form.

    From what you say you want, assuming that Form1 contains the controls txtName and txtAge, you would do something like this:
    VB Code:
    1. 'Form1 code
    2. Private Sub btnSubmit_Click(ByVal sender as System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    3.     Dim Form2 As New frmMain2
    4.  
    5.     With Form2
    6.         .txtName.Text = txtName.Text
    7.         .txtAge.Text = txtAge.Text
    8.     End With
    9. End Sub

    I know this is most probably wrong but it's the best I could do with your example as it conflicts with itself.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width