?
Solved

How do I set a global variable in VB.NET

Posted on 2010-01-11
5
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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