Object Global Information

jackgreat

Active member
Joined
Apr 17, 2006
Messages
35
Programming Experience
1-3
Hello Everyone,

I am a VB6 user who has recently moved to Visual Basic 2005.

I am using classes and had a query. I have a login class and in my project i want login information like valid or not etc to be available to every form.

Now the problem is if i instantiate that class and i put value using that object then every object maintains its own copy so how will i access that copy in some other form.

One way is to declare shared variable whom we can access throught the project. Is there any other way we can instantiate a class and the properties of that object can be accessed anywhere in class. (obj reference).

Will be grateful if anyone can help.

Thanks a lot,

Cheers,
JG
 
personally i would add a module to the project and declare a variable such as:
Friend gblnLoggedIn As Boolean = False

now in the login form, if they successfully log in set this variable to True then in the other forms just check that variable to see that it's true

by declaring that variable as Friend it has the scope of the entire program, all forms and classes have access to it but programs outside of that one running can't get to it because it's declared as Friend instead of Public
 
I've stopped using modules altogether in VB 2005. If you go to the Application tab of the project properties and click the View Application Events button it will open the code file for the MyApplication class. It is a global instance of this class that you access through the My.Application object. If you declare a public variable named MyVariable in that code file it will be available throughout your app as My.Application.MyVariable. I think that the use of the qualifying expression is appropriate, although it does require five additional key presses than if you used a module, where you can use the members unqualified.
 
Back
Top