Register | Login | |||||
Main
| Memberlist
| Active users
| ACS
| Commons
| Calendar
| Online users Ranks | FAQ | Color Chart | Photo album | IRC Chat |
| |
0 user currently in Programming. | 3 guests |
Acmlm's Board - I2 Archive - Programming - VB Variables and Modules question | | | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
User | Post | ||
RoboticParanoia Cheep-cheep Level: 23 Posts: 80/184 EXP: 60582 For next: 7141 Since: 03-23-04 From: Texas Since last post: 150 days Last activity: 150 days |
| ||
Here is my question: Let's say you created some public variables on a form. Can these variables be referred to (like let's say through If...Then statements or whatever) on a public module? If not, then how can I get it to work so that the variables can be referred on the module? |
|||
Darth Coby Vire Dacht je nou echt dat het over was? Dacht je nou echt dat ik gebroken was? Nee toch? Nou kijk eens goed op uit je ogen gast. zonder clic heb je geen kloten tjap... bitch Level: 55 Posts: 783/1371 EXP: 1240774 For next: 73415 Since: 03-15-04 From: Belgium Since last post: 2 days Last activity: 9 hours |
| ||
Not sure about variables, but I know you can use parts of a form in a module. Just use With formname bla bla code bla .txtTextfield = blabla That might work with variables too. |
|||
interdpth Rex Level: 36 Posts: 90/527 EXP: 294398 For next: 13712 Since: 03-20-04 Since last post: 10 days Last activity: 31 days |
| ||
Prolly if you declare them in a type like this Private Type tType one as integer two as string end type private Type() as tType For calling the variables use Private. Variable |
|||
Deleted User Banned Level: 8 Posts: 1/12 EXP: 1736 For next: 451 Since: 01-23-01 Since last post: 13089 days Last activity: 21 days |
| ||
The form has to be loaded to memory. That is, no unload form, or the variable goes to hell. But it's a generally bad idea to declare global variables in forms. You'd be much better off just loading the module from the start manually and declaring the variable there. | |||
dormento Shyguy Level: 17 Posts: 35/99 EXP: 24075 For next: 668 Since: 03-15-04 From: Esteio - Brasil Since last post: 182 days Last activity: 161 days |
| ||
Like Lord Duran said, there's really no incentive whatsoever to declare public variables on a form. If you want your variables to be seen outside of the form, declare them in a module. Tip: You can avoid some problems putting Option Explicit on the top of your forms and code modules. It tells Visual Basic to assume that any reference to an undeclared variable is an error. If there's no Option Explicit, every time you reference a variable that isn't declared, VB silently creates a variable of type Variant (versatile but slow and bloated ). What i generally do is to create a module where i declare all my constants and public variables, types, enums etc. If you're really really desperate about acessing a form's public variables from inside a module, you can do {formname}.{variablename}=... , but as LD said, the variable goes poof when the object is unloaded. Hope that helps |
|||
RoboticParanoia Cheep-cheep Level: 23 Posts: 83/184 EXP: 60582 For next: 7141 Since: 03-23-04 From: Texas Since last post: 150 days Last activity: 150 days |
| ||
Well, thank you everyone. There's generally going to be only one form...I just kinda wanted to make my software a bit more open, so people can add more features (or in my case, a game), and I thought using modules might work. I guess I'll toy around with it for a while. |
|||
HyperLamer <||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people Sesshomaru Tamaranian Level: 118 Posts: 1253/8210 EXP: 18171887 For next: 211027 Since: 03-15-04 From: Canada, w00t! LOL FAD Since last post: 2 hours Last activity: 2 hours |
| ||
DON'T DO IT! If you refer to something in a form that's not loaded, it'll automatically load, and you'll go aaaaarrrggghhh trying to figure out WTF happened. All public variables and functions should be put in modules, unless you have a form that is always loaded. | |||
RoboticParanoia Cheep-cheep Level: 23 Posts: 85/184 EXP: 60582 For next: 7141 Since: 03-23-04 From: Texas Since last post: 150 days Last activity: 150 days |
| ||
I figured out how to work it out, so everything is a-okay. The only thing now, is the subroutines, and the file organization...which I'm terrible at. =P But, thank you everyone, for your help, I appreciate it. |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
Acmlm's Board - I2 Archive - Programming - VB Variables and Modules question | | | |