Click to See Complete Forum and Search --> : Public Variable help please


Simon Phillips
October 16th, 2001, 10:38 AM
Oopps. Posted this in wrong category initially!

Can anyone PLEASE help with what I am sure is a simple problem! I have a VB6 project where the initial form is called 'menu.frm'. In the 'General Declarations' section of this form I have the following lines :


option Explicit
public superpass as string




In the 'Form Load' event of 'menu.frm' I assign a value of "test" to 'superpass'. If I reference 'superpass' within any code inside 'menu.frm' I get the correct contents (The string "test"). If I reference 'superpass' from code inside another form in the same project it is empty!! Please help - I want to be able to create a global variable at the start of my program that is available anywhere.

Cimperiali
October 16th, 2001, 10:43 AM
Public in general section of a form module becomes a property of that form. If you need a global variable inside your project, you may add a .bas module (=standard module) and declare there that variable as Public


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

DSJ
October 16th, 2001, 10:53 AM
Try using menufrm.superpass

Cimperiali
October 16th, 2001, 10:57 AM
He is right but remember: this will cause your form to be loaded even if unloaded each time you use that "variable" from somewhere else (your Form will not be loaded twice if already loaded); while usiong a public variable in a bas module, you will be use only a variable and do not cause the loading of any form...

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Simon Phillips
October 16th, 2001, 11:01 AM
Thanks to both of you ! Both methods work and I remembe.ed about the sep. module bit when you mentioned it. I am coming back to VB after some time away from it and am a little rusty. It's great to see some support out there though - Once again, Thanks very much.

Cimperiali
October 17th, 2001, 02:12 AM
You're welcome.


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater