Accessing a variable on another form
-
I have a variable on another form that I need to read and write to. I know it'll be obvious once someone tells me... Just for the record, the form with the variable I'm trying to access is frmMainTools and the one I'm trying to access from is frmMain. A timely answer would be most helpful. Thanks! --------------------------------------- If it ain't broke, you're not tryin'!
-
I have a variable on another form that I need to read and write to. I know it'll be obvious once someone tells me... Just for the record, the form with the variable I'm trying to access is frmMainTools and the one I'm trying to access from is frmMain. A timely answer would be most helpful. Thanks! --------------------------------------- If it ain't broke, you're not tryin'!
The easiest method is to declare the variable on frmMainTools as public.
-
I have a variable on another form that I need to read and write to. I know it'll be obvious once someone tells me... Just for the record, the form with the variable I'm trying to access is frmMainTools and the one I'm trying to access from is frmMain. A timely answer would be most helpful. Thanks! --------------------------------------- If it ain't broke, you're not tryin'!
The best way to do this is to set up a delegate between the forms that fires the value across when it is changed. This is far cleaner than making variables public.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
The easiest method is to declare the variable on frmMainTools as public.
-
The easiest method is to declare the variable on frmMainTools as public.
Maybe the easiest, but not the best in terms of OOP. Globals are not good :)
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Dim mCurrentForm As Form How would one make that public when it is already declared as a Form?
Looks like I got it figured. Thanks for the help and speedy responses. The fact that this is going to be an app for just this company and it's a rather small app causes me to not worry about messy code. It doesn't need to work fast and besides that, it's only a database front-end, so I'm not going to be too worried if it breaks. Thanks again! -------------------------------- If it ain't broke, break it!