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
Printable View
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
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
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.
I'm sorry but I have to disagree with those suggestions.Quote:
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
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.
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
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.Quote:
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?