Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

global variables

Status
Not open for further replies.

clientuser

Programmer
Apr 18, 2001
296
US
is it looked down on to set a global variable in a module to be referenced throughout an application?

for instance, i have a username that i need to save somewhere while the user is logged in and it can then be deleted after the user logs out of the app.. what is the best method to hold variables and have them used throughout an entire application? any examples would be greatly appreciated
 
A public variable in a code module is the best way to go.

Declare it like this in a code module, once its loaded you can then use it anywhere in the app

Public psUserName As String
 
global variable is the simplest way to achieve your task.

However, if you want to go advanced, you can store the details of the logins in a small table in your database.

this table will have a row for each user.

it will store info like : username, log in time, module currently used and so on.

you will need to update the module used field for the users,, as and when they navigate in your application.

on regular exit/logoff delete the user's row in the table.

in event of a abnormal termination, you will have the details of the module from where the event happened.

this is a basic idea. . .you can be more creative on these lines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top