Public Variable help please
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.
Re: Public Variable help please
I believe you need a seperate module to hold the "public superpass as string" and only then does it become truly global.
I usually make my modile named modGlobals so I know what's stored there...
As it is now, your variable's scope is limited to your menu.frm.
Re: Public Variable help please
>If I reference 'superpass' from code inside another form [...]
At the beginning of each form/module do you have the statement "Option Explicit"?
If no, each time you're referring to a different thing. Correct sintax to access what is a property of the form (=a public variable in a form becomes a property of the form) is FormName.PropertyName
ie:
'in Form2
dim localstring as string
localstring = Form1.superpass
Otherwise, you're simply creating each time a new variant variable...
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