|
-
October 16th, 2001, 10:35 AM
#1
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.
-
October 16th, 2001, 11:01 AM
#2
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.
-
October 17th, 2001, 08:12 AM
#3
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
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
October 17th, 2001, 08:15 AM
#4
Re: Sooorry!!
Did not remember I already saw this in another category.
Sorry, fellow.
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
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|