NeverDie
12-08-2001, 03:12 PM
I am making a game that requires a variable to be used between multiple forms. How does one accomplish this?
Using variables between formsNeverDie 12-08-2001, 03:12 PM I am making a game that requires a variable to be used between multiple forms. How does one accomplish this? dcl3500 12-08-2001, 04:06 PM 2 Choices actually. 1. Put in a module and declare the variable like this: public myVar as 'whatever datatype you want it to be. 2. Declare the variable like this on the form: public myVar as 'whatever datatype you want it to be. and then when you need to use it on the other form use it like this: form1.myvar Where form1 is the name of the form where the variable is declared. One thing to remember though with this method though. The form where the variable is declared must be loaded to use the variable. NeverDie 12-08-2001, 05:36 PM Alright, and any suggestions on where I could find some information on using modules (such as what theyre for :) )? I am not very experienced with them. thanx. Banjo 12-08-2001, 06:49 PM Module is just a collection a subs and functions. They are accessable from anywhere in the project. To add a module, right-click on the Project window, select Add>>Module and then select the Module template. You can then just enter variable declarations, subs and functions. Squirm 12-08-2001, 06:51 PM Imagine a form, without the form part, just the code window part. As you gain experience with VB you will be using them more and more images/icons/smile.gif NeverDie 12-08-2001, 07:52 PM I'm liking them already, thanx :) wild wolf 12-09-2001, 09:21 PM hmmm, what if i declare the function in the form but the first thing i declare is Option Explicit, do u think that can work? Volte 12-10-2001, 02:33 PM Ummm, excust me? Option Explicit has to be the first thing there, if it's going to be anywhere. If you declare a function in the form, it must go under Option Explicit. |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum