![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
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,
|
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 372
Rep Power: 0
![]() |
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.
__________________
I am Addicted to Linux! |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jan 2005
Location: Bayamon, Puerto Rico
Posts: 71
Rep Power: 4
![]() |
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 Integer
Get
Return myPopertyVar 'myPropertyVar is dlecared outside this code
End Get
Set(ByVal Value As Integer)
myPropertyVar = Value
End Set
End PropertyIf I mistake what you are trying to do please reply and ill try to give you a more accurate answer -codetaino
__________________
"God bless u all" :) |
|
|
|
|
|
#4 | |
|
Newbie
Join Date: Sep 2006
Location: Fl
Posts: 5
Rep Power: 0
![]() |
Quote:
Create a module and store you variables in the module. Then you can just reference the variables by modulename.variablename.. |
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 211
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#6 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5
![]() |
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.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
|
you could raise an event and pass the data through event args.
__________________
I have never let my schooling interfere with my education. -Mark Twain- Xbox live gamertag: melbolt |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple conditions in an #ifdef statement | JawaKing00 | C | 8 | Apr 26th, 2006 4:11 PM |
| Storing variables to a file? | Oddball | PHP | 2 | Mar 21st, 2006 2:09 PM |
| [Efficiency] Variables vs. Calculations | kurt | C | 7 | Dec 29th, 2005 2:39 PM |
| Dynamic memory - variables | darkone916 | C++ | 4 | Dec 7th, 2005 6:24 AM |
| multiple definition of variables in include files | carlgreen | C++ | 3 | Feb 26th, 2005 7:02 PM |