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!

using "global variables " in vb.net 2012

Status
Not open for further replies.

jpower69

Programmer
Feb 5, 2008
54
US
I am new to VB.NET 2012.

I have been using VFP9 for a long time. In VFP(, i can create a global variable that will be available thought the entire application
I am in the process of converting a login screen into VB.NEt from VFP9.
I have the following code set up in my form:
Public Class Login
'
' setup global variables here- hopefully
' 08/13/14
' jp
'
Public guserid As String = ""
Public guserrights As String = ""
Public gfiaccess As String = ""
Public guserfull As String = ""
'
' end of global variables
'

the variable guserid is populated from a textbox entered my the user.
My question is how can I pass the variable guserid to different forms, form2 thru formx

If this has been answered before, can you please send me the link or let me know how i do this as I have several "global variables"
to process
Any comment/suggestions greatly appreciated

thans you in advance
 

Check out this FAQ:

faq796-5773

It's older, but everything is it is still valid.

If you want to have variables that are global to the entire project, add a Module and declare them as either Public or Friend there. You can then access them anywhere in the project either by just the name, or by <module name>.<variable name>. If you do this, I recommend always using <module name>.<variable name> as it makes it much easier to debug.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
I would strongly suggest: Avoid Global variables. Do use Global Constants, but not global / public variables. There are better / safer ways to pass data between Forms. See jebenson's link

The only Global variables I would use are the once you set only once and never, ever change. Something like UserName, ComputerName, UserRole, etc. Any global variables that you will change in your code in several places is just asking for trouble.

Just my opinion…


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Thanks for the fast replies and information
The global variables will be used for user name, user Id, etc., items that will not changed
through out the application.

again thanks for the information

will let you know the results

 
just a follow up

I created my module global_vars
Module global_vars
'
' setup global variables here- hopefully
' 08/13/14
' jp
'
Public guserid As String = ""
Public guserrights As String = ""
Public gfiaccess As String = ""
Public guserfull As String = ""
'
' end of global variables
'


End Module

and I populate the variable guserid with global_vars.guserid = myreader.Item("id")
then i populate a variable in my third form with Luserid = global_vars.guserid
so it appears to work

thanks for the help


 
in my third form with Luserid = global_vars.guserid"
Why do you have another (Luserid) variable? Why not just use global_vars.guserid?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
wanted to make sure it was passing the data

I will bypass that statement but for now going to leave it as it

again thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top