Pass data from Form A to Form B

Suppose that Form A has a button that when clicked creates Form B.

How do you pass information from Form A to Form B?

Comments

  • : Suppose that Form A has a button that when clicked creates Form B.
    :
    : How do you pass information from Form A to Form B?
    :
    :
    What specific data would you want to pass?

    you could pass all sorts of Data are you looking at passing text, images, ECT?

  • : : Suppose that Form A has a button that when clicked creates Form B.
    : :
    : : How do you pass information from Form A to Form B?
    : :
    : :
    : What specific data would you want to pass?
    :
    : you could pass all sorts of Data are you looking at passing text, images, ECT?
    :
    :

    Assuming you want to pass an integer:

    In Form B

    #Region " Windows Form Designer generated code "

    Public Sub New(ByVal xValue As Integer)

    valX = xValue


    #End Region

    'Before Form Load
    Dim valX As Integer


    In Form A:
    'Code behind Button

    dim xValue as integer

    xValue = 20 'Or any integer value you want to pass
    Dim frm As New frmB(xValue)


    Hope this helps.























  • : : : Suppose that Form A has a button that when clicked creates Form B.
    : : :
    : : : How do you pass information from Form A to Form B?
    : : :
    : : :
    : : What specific data would you want to pass?
    : :
    : : you could pass all sorts of Data are you looking at passing text, images, ECT?
    : :
    : :
    :
    : Assuming you want to pass an integer:
    :
    : In Form B
    :
    : #Region " Windows Form Designer generated code "
    :
    : Public Sub New(ByVal xValue As Integer)
    :
    : valX = xValue
    :
    :
    : #End Region
    :
    : 'Before Form Load
    : Dim valX As Integer
    :
    :
    : In Form A:
    : 'Code behind Button
    :
    : dim xValue as integer
    :
    : xValue = 20 'Or any integer value you want to pass
    : Dim frm As New frmB(xValue)
    :
    :
    : Hope this helps.
    :
    :
    :
    : That helps alot...I wasn't aware of the "New" method. Seems like I should have been since it's basicly a constructor for the form!

    Thanks a bunch!
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :

  • : : : : Suppose that Form A has a button that when clicked creates Form B.
    : : : :
    : : : : How do you pass information from Form A to Form B?
    : : : :
    : : : :
    : : : What specific data would you want to pass?
    : : :
    : : : you could pass all sorts of Data are you looking at passing text, images, ECT?
    : : :
    : : :
    : :
    : : Assuming you want to pass an integer:
    : :
    : : In Form B
    : :
    : : #Region " Windows Form Designer generated code "
    : :
    : : Public Sub New(ByVal xValue As Integer)
    : :
    : : valX = xValue
    : :
    : :
    : : #End Region
    : :
    : : 'Before Form Load
    : : Dim valX As Integer
    : :
    : :
    : : In Form A:
    : : 'Code behind Button
    : :
    : : dim xValue as integer
    : :
    : : xValue = 20 'Or any integer value you want to pass
    : : Dim frm As New frmB(xValue)
    : :
    : :
    : : Hope this helps.
    : :
    : :
    : :
    : : That helps alot...I wasn't aware of the "New" method. Seems like I should have been since it's basicly a constructor for the form!
    :
    : Thanks a bunch!
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    :
    :
    Or by
    Dim Shared X as String (in formA)

    then in formB
    you could set varible Y - formA.X


  • : : : : : Suppose that Form A has a button that when clicked creates Form B.
    : : : : :
    : : : : : How do you pass information from Form A to Form B?
    : : : : :
    : : : : :
    : : : : What specific data would you want to pass?
    : : : :
    : : : : you could pass all sorts of Data are you looking at passing text, images, ECT?
    : : : :
    : : : :
    : : :
    : : : Assuming you want to pass an integer:
    : : :
    : : : In Form B
    : : :
    : : : #Region " Windows Form Designer generated code "
    : : :
    : : : Public Sub New(ByVal xValue As Integer)
    : : :
    : : : valX = xValue
    : : :
    : : :
    : : : #End Region
    : : :
    : : : 'Before Form Load
    : : : Dim valX As Integer
    : : :
    : : :
    : : : In Form A:
    : : : 'Code behind Button
    : : :
    : : : dim xValue as integer
    : : :
    : : : xValue = 20 'Or any integer value you want to pass
    : : : Dim frm As New frmB(xValue)
    : : :
    : : :
    : : : Hope this helps.
    : : :
    : : :
    : : :
    : : : That helps alot...I wasn't aware of the "New" method. Seems like I should have been since it's basicly a constructor for the form!
    : :
    : : Thanks a bunch!
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : :
    : :
    : Or by
    : Dim Shared X as String (in formA)
    :
    : then in formB
    : you could set varible Y - formA.X
    :
    :Does the New() method have to be in the windows generated code region?
    :I'm wondering now, because I tried this method and during runntime, when i called the form without arguments, the form would show as designed, but if I called the form with arguments, a blank form would show. I had the New() method outside of the windows generated code region, now I wonder if this is the reason why.
    :
    :



  • : : : : : : Suppose that Form A has a button that when clicked creates Form B.
    : : : : : :
    : : : : : : How do you pass information from Form A to Form B?
    : : : : : :
    : : : : : :
    : : : : : What specific data would you want to pass?
    : : : : :
    : : : : : you could pass all sorts of Data are you looking at passing text, images, ECT?
    : : : : :
    : : : : :
    : : : :
    : : : : Assuming you want to pass an integer:
    : : : :
    : : : : In Form B
    : : : :
    : : : : #Region " Windows Form Designer generated code "
    : : : :
    : : : : Public Sub New(ByVal xValue As Integer)
    : : : :
    : : : : valX = xValue
    : : : :
    : : : :
    : : : : #End Region
    : : : :
    : : : : 'Before Form Load
    : : : : Dim valX As Integer
    : : : :
    : : : :
    : : : : In Form A:
    : : : : 'Code behind Button
    : : : :
    : : : : dim xValue as integer
    : : : :
    : : : : xValue = 20 'Or any integer value you want to pass
    : : : : Dim frm As New frmB(xValue)
    : : : :
    : : : :
    : : : : Hope this helps.
    : : : :
    : : : :
    : : : :
    : : : : That helps alot...I wasn't aware of the "New" method. Seems like I should have been since it's basicly a constructor for the form!
    : : :
    : : : Thanks a bunch!
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : :
    : : :
    : : Or by
    : : Dim Shared X as String (in formA)
    : :
    : : then in formB
    : : you could set varible Y - formA.X
    : :
    : :Does the New() method have to be in the windows generated code region?
    : :I'm wondering now, because I tried this method and during runntime, when i called the form without arguments, the form would show as designed, but if I called the form with arguments, a blank form would show. I had the New() method outside of the windows generated code region, now I wonder if this is the reason why.
    : :
    : :
    :
    :
    :
    :
    Im not sure if it will make a difference, I have only tried it with the code in the windows generated code.
  • It does not matter where it is, basically you are overloading the constructors funciton's signiture. When you do this which is fine make sure to call the componentInit function for the form(I forget what it is called look in the generated constructor). If you dont call this function it won't create the controls for the IDE.

    ~rlc



  • Another possilbilty would be if you need to populate a label or text box to simply assign a value to the text property...

    dim fb as new formb

    fb.label1.text = "The text you need to pass"

    any object in formb is accessible with this method


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories