referencing variable across forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • willywonka
    New Member
    • Sep 2007
    • 18

    referencing variable across forms

    Hi again! hope there is no limit to posting newbies questions but this will probably be my last one for a while! I have managed to find some answers to other questions in my mind on here..yippy!

    Ok i wanted to know how to refer to a variable from (maybe from a text box) on one form to another form. I have managed to refer to them currently by passing them along to each new created form everytime (one by one) but wanted to refer to a variable from form 1 to say form 5, how can i do this? I read something about creating a Module..would that be just like creating forms instead and then all the variables will be global?

    Thank you for any knowledge u can impart!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by willywonka
    Hi again! hope there is no limit to posting newbies questions but this will probably be my last one for a while! I have managed to find some answers to other questions in my mind on here..yippy!

    Ok i wanted to know how to refer to a variable from (maybe from a text box) on one form to another form. I have managed to refer to them currently by passing them along to each new created form everytime (one by one) but wanted to refer to a variable from form 1 to say form 5, how can i do this? I read something about creating a Module..would that be just like creating forms instead and then all the variables will be global?

    Thank you for any knowledge u can impart!
    Which language are you using?
    Making everything global is so un-OOP and you shouldn't do it. It really is a good sign of bad program design.

    Comment

    • willywonka
      New Member
      • Sep 2007
      • 18

      #3
      i am using .net and created a window's application...i want to know how to reference variables across different forms (form 1 to form 5)so if u could please sugguest on how to do that.

      Thanks.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by willywonka
        i am using .net and created a window's application...i want to know how to reference variables across different forms (form 1 to form 5)so if u could please sugguest on how to do that.

        Thanks.
        Which .NET language? VB, C#, J#?
        You'll also need to explain what the variable does and it's purpose because that decides the best way of creating it.
        e.g You could pass it as a parameter to a method, you could make it static in one of the classes, you could write its value to a file/socket and retrieve it in one of the other form's method, e.t.c (and there are other more exotic approaches). The correct approach depends on the context and purpose of the variable.

        Comment

        • willywonka
          New Member
          • Sep 2007
          • 18

          #5
          thanks for ur assitance thus far...opps sorry i am using vb.net. i have created a few variable's which are the text entered into a text box in my 2nd form (someone's name, address, phone number). I then want to use these variables in my 5th form and also pass them as parameters to some methods that are called in the 5th form once a button is pressed. not sure how to access them, i have tried form1.name /name.form1 but have been extremley unsucessfully.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by willywonka
            thanks for ur assitance thus far...opps sorry i am using vb.net. i have created a few variable's which are the text entered into a text box in my 2nd form (someone's name, address, phone number). I then want to use these variables in my 5th form and also pass them as parameters to some methods that are called in the 5th form once a button is pressed. not sure how to access them, i have tried form1.name /name.form1 but have been extremley unsucessfully.

            Check out this .NET article on Sessions - How to pass information between web pages.

            Cheers
            -Frinny

            Comment

            Working...