![]() |
Storing Variables with Multiple Dialogs/Forms
The Project that I am currently working on contains 6 different Dialog Boxes. It is the same idea of installing a program of after you've entered in certain info you go on to the next screen. I'm fine with that my problem is storing the variables in a location that wont change. I created a main class that will hold all the variables. The Problem is when ever I reference it as "Dim MainClass as New Main", it resets all the varibles, does anyone knoe how to store varibles between multiple dialogs/form windows? So When I set a variable in Form1 that in Form6 it will be what I had set it to in Form1. Thanks,
|
When you create each new form you could pass the variables to it. I am not too familiar with VB, but you probably also make a static class.
|
If I understand correctly you want a variable that stays the same no matter how many times you create a new instance of the main object? If this is the case then what you need is to reasearch about what is called in other languages as static members (in vb.net Shared Members) This type of members will be the same in all the instances you create of the class. A change in one instance will affect others. an example of a declaration of a shared property could be:
:
Public Shared Poperty myProperty() As IntegerIf I mistake what you are trying to do please reply and ill try to give you a more accurate answer -codetaino |
Quote:
Create a module and store you variables in the module. Then you can just reference the variables by modulename.variablename.. |
King has two valid ways of doing this, I'd be apt to lean towards the variable passing method than the static class method, however it you're only using it for these 6 variables a static class might be the way to go.
I've seen too many projects where 'static' class variables tend to become a dumping ground for global variables without actually calling them global variables. However, the downside to passing the information back and forth, is you actually need to keep track of it, and pass it back and forth. -MBirchmeier |
One thing you could do is declare the instance as public, and then just reference it from the other classes. To avoid having it be a plain global, you can make each variable a property of the class. Taking this one further, you could make this public instance a public property of one class, and then each other class could access it. Properties in VB (indeed, all the .NET languages that support them) are like public variables, except each is actually accessed through a custom function, so you can provide validation and adjust other members (properties or otherwise) if one property changes.
|
you could raise an event and pass the data through event args.
|
| All times are GMT -5. The time now is 1:06 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC