sharing data between forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al_C

    sharing data between forms

    As mentioned earlier I've been away from coding for about 5 years. Know I
    know why :(
    I've been trying to work out a critical detail, hard to do on Thanksgiving
    ;)
    Push a button on form1, form2 appears, I enter some text push a button and
    get the data back to form1.
    In the "old days" we had globals to pass stuff like this through. (as a C
    programmer by background
    I always found that pretty poor). But now I can't find a mechanism to do
    what I want. I've done a lot of MSN and google searching but nothing that
    works.
    (have to admit, I really need to change my Fileopen and other classic basic
    code to .net)
    Thanks to all, and hope you had a great day of turkey.




  • iwdu15

    #2
    RE: sharing data between forms

    whenever i want to share info between forms, usually i create a module. i
    dunno if its the rite way to do it, being only a n00b programmer at the age
    of 16, but i create a new module and create a variable in the body which you
    can store info in, for example

    ''code in module

    Public strNames as String

    ''make it public so all forms can access it

    ''in your code of your form

    private sub btnclick_click( ...)handles...

    module1.strName s = me.textbox1.tex t

    end sub

    then you can just read in the variable and write to it

    hope this helps
    --
    -iwdu15

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: sharing data between forms

      Al,

      There are probably thousand of possibilities.

      However the first question you have to ask yourself is it
      a dialogform
      a normal (existing beside the other form)
      a mdi (existing inside the main form)

      If it is a dialogform than it is very simple and basicly

      \\\
      dim frm as new myform
      frm.PublicValue = Mywhatever
      frm.Showdialog
      myWhatever = frm.PublicValue
      frm.dispose
      ///

      I hope this helps,

      Cor


      Comment

      • Brad Rogers

        #4
        Re: sharing data between forms

        I will try to help, start by designing your main form. In the Solutions
        window, right click on the solution name and click on Add, then Add Windows
        Form, and name it popupForm, then add your text box and 2 buttons. Get the
        physical stuff out of the way. If you start by just letting the new form be
        called default 'form2.vb' then thats fine too

        In the button click event to make a new form2, you would create an instance
        of the form with a Dim, you get there by double clicking on the button you
        created, and inside the routine type the handler, then also for button 2 add
        the other handler

        keeping in mind Form2 is popupForm

        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
        System.EventArg s) Handles Button1.Click

        Dim dataentry As New popupForm

        dataentry.Show( )

        End Sub

        Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
        System.EventArg s) Handles Button2.Click

        Me.TextBox1.Tex t = popupForm.strin garray

        End Sub

        Yes, technically you could create a sub to handle your new popup forms
        creation and whatever, this is for example use

        In the form2 or popupForm, create a textbox and a button, double click the
        button

        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
        System.EventArg s) Handles Button1.Click

        stringarray = Me.TextBox1.Tex t.ToString

        End Sub

        Now, do you want the text in your main form1 to change whenever text in the
        other form changes? Thats far more complicated and should be part of a new
        upgrade to VB release 3?

        Anyhow, to update the first textbox the only way I know of is to use a thing
        called an Observer Pattern. The changing data in the textbox triggers an
        update event and the form1 textbox has to be subscribed by giving its
        address to the event.

        If anyone knows another way? Im interested to hear it





        "Al_C" <aclapp@bicnet. net> wrote in message
        news:%23kvw3GW8 FHA.132@TK2MSFT NGP15.phx.gbl.. .[color=blue]
        > As mentioned earlier I've been away from coding for about 5 years. Know I
        > know why :(
        > I've been trying to work out a critical detail, hard to do on Thanksgiving
        > ;)
        > Push a button on form1, form2 appears, I enter some text push a button and
        > get the data back to form1.
        > In the "old days" we had globals to pass stuff like this through. (as a C
        > programmer by background
        > I always found that pretty poor). But now I can't find a mechanism to do
        > what I want. I've done a lot of MSN and google searching but nothing that
        > works.
        > (have to admit, I really need to change my Fileopen and other classic[/color]
        basic[color=blue]
        > code to .net)
        > Thanks to all, and hope you had a great day of turkey.
        >
        >
        >
        >[/color]




        Comment

        Working...