Results 1 to 7 of 7

Thread: Variables between forms

  1. #1

    Thread Starter
    Member
    Join Date
    May 2002
    Location
    Merry Olde England
    Posts
    57

    Question Variables between forms

    How can I read (get the contents of) a variable on one form to read in another?

    e.g. I have a variable ABC defined in form1, and I want to see what it's data is in form 2.

    thx

  2. #2
    Addicted Member
    Join Date
    Jan 2003
    Posts
    163
    possibilities
    1) use a global variable
    2) create an invisible text box on form1 and have form2 get the contents
    3) create a temp file in form1 and have form2 read it

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    add public let/get property procedures in the forms
    add public variables in the forms

    I'd recommend the property procedures so you can do some handling on the incoming/outgoing data to ensure it will be valid for use in other forms.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Originally posted by john24
    possibilities
    1) use a global variable
    2) create an invisible text box on form1 and have form2 get the contents
    3) create a temp file in form1 and have form2 read it
    I'm sorry but I have to disagree with those suggestions.
    1) Global variables, while the best of the 3 solutions you gave, have problems that we can discuss if you like, but for now let me say it's best to just avoid them if you can
    2) I don't see any benefit in creating an invisible text box
    3) File I/O is one of the most time-consuming activities in VB and you certainly don't have to use it just to pass values between forms.

    Here are my suggestions:

    1) Create a Property on Form1. See my posts in this thread for an example
    2) Simply Dim the variable as Public in the form. You can then refer to it via something like Form1.intVarValue. That is similar to a Global variable but the scope is less and that's a good thing.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2002
    Location
    Merry Olde England
    Posts
    57

    Thumbs up

    Dimming the variable as public is a great solution thx admin guy. temp files and invisable txt boxes would create slowdown, and ur advice on the gobal variables is taken.

    Thx to all posters

  6. #6
    Addicted Member
    Join Date
    Jul 2000
    Location
    FeedMeTown, Ohio
    Posts
    176
    hmmm... I may be missing something...

    I've always used modules to declare public variables.

    Ex.:

    Option Explicit
    Public ABC as Variant

    Is not Public the same thing as Global?
    Never tie a rock to your ankle while randomly selecting stones to throw from high places.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Originally posted by EZapps
    hmmm... I may be missing something...

    I've always used modules to declare public variables.

    Ex.:

    Option Explicit
    Public ABC as Variant

    Is not Public the same thing as Global?
    Yes. Public is a newer way of making something global. "Global" still works of course.

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