Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I declare modular level variables?

Status
Not open for further replies.

daldous

Technical User
Feb 23, 2002
22
0
0
US
Hi,

How do I declare modular level variables (or get 2 forms to talk to each other somehow!!)

I have declared Public variables in the Declarations section of Form1. When I added a 2nd form, Form2, code written in Form2 does not see the variables from Form1. (I added Form2 with the Add Form Dialog and it isn't a "child".)

I don't get it. All I am trying to do is add a large picture (image) of a jpeg photograph on Form2. Code in Form1 can't seem to direct activities on Form2 and Code on Form2 can't seem to use variables (even system variables like "Path") from Form1.

I have looked for hours through 4 aftermarket books on VB6 and can't find the answer. I feel stupid asking such a simple question. Obviously, I don't try to make a living as a programmer!!

Thanks in advance!

daldous
 
You've made the variable Modular, but to have it available to two or more forms, you'd have to make it Global. You have to declare the variables Public in a standard module (i.e. a .bas file) rather than in the General Declarations on a form. Doing it on Form1 only makes the variables available to subs on that form.

The easy way to make variables from one form available to another form is to refer to them by their form object name.

If you are in Form2, and you need to refer to a MyVariable from Form1, you would simply refer to it as:

Form1.MyVariable

Hope this helps "It's got to be the going,
not the getting there that's good!"
-Harry Chapin
 
You sort-of answered your own question (i.e. modular level variables :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top