Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Pass data from Form A to Form B

SteveWaltariSteveWaltari Posts: 4Member
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

  • biohazard 2.0biohazard 2.0 Posts: 30Member
    : 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?

  • GrinjaGrinja Posts: 26Member
    : : 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.























  • SteveWaltariSteveWaltari Posts: 4Member
    : : : 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!
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :

  • paulmorrisonpaulmorrison Posts: 127Member
    : : : : 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


  • SteveWaltariSteveWaltari Posts: 4Member
    : : : : : 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.
    :
    :



  • GrinjaGrinja Posts: 26Member
    : : : : : : 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.
  • rlcrlc Posts: 448Member
    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

  • digitalgeekdigitalgeek Posts: 59Member


    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.