Dealing with Multiple Forms


#1

I’m writing a single program that contains multiple ‘games’. Each game is on a separate form. There is one Function that is used by the (currently) two forms. I currently have duplicated that function in both forms, using the same function name and the same variables.

Question: Are there any ‘does’ and ‘don’ts’ that are unique to multi-form programs? e.g., can I call a function from form 2 that is located in form 1? Can I use variables that are created in another form? What other pit falls are there (if any)?

The issue that I’m currently having is that the form 1 ‘game’ works perfectly if I totally comment out the form 2 game… and form 2 works if form 1 is commented out (totally) … but if BOTH are active, neither one runs correctly.


#2

If I recall correctly, “form” is a bit of a misnomer, because in the end the application becomes one big file. If that’s the case, then you would not be able to have two functions with the same name.

Eric


#3

Thanks, Eric… that was the problem… I was treating each ‘form’ as a separate program and therefore there were duplicate variable names and functions.

Tom


#4

That’s right - it’s all one big variable space.

If you have functions and variables that are used by multiple forms, you can put them into Global Code to make it clear that they are not specific to a particular form.