Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I set a global variable in VB.NET

Posted on 2010-01-11
5
Medium Priority
?
297 Views
Last Modified: 2012-05-08
I need to set a variable that will be available throughout the application.  Is there any way to do this in VB.NET?  I want to keep track of the user that's logged in.

Thank you
0
Comment
Question by:Agent909
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 26285458
you can create a public variable into a Module. It will be globally available .
0
 
LVL 15

Accepted Solution

by:
x77 earned 1000 total points
ID: 26285510
A shared variable do´nt need a instance.
if it is on a Class/Structure, you need use MyClass.MyVar notation to access it.
On a module, all variables are shared. No prefix is required.
Declare the variable as Public if you need access it from other class or module.

on a class:
  Public shared MyVar as new List(of string)

on a Module:
  Public MyVar as New List(of String)
0
 
LVL 2

Expert Comment

by:swapneel_d14
ID: 26285514
Declare session variable
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 26286422
Or you can have application variable set at global.asax
0
 
LVL 1

Author Closing Comment

by:Agent909
ID: 31675602
You helped me with both situations:  in a Module or in a Class.  Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question