|
I come from a web background. Therefore I am used to being able to use cookies and session variables to pass information around the application.
The only way I have figured out how to pass information on to another windows form is to set the value to a hidden field somewhere on the next form. There has to be a better way to do this. Can anyone explain to me how I can set up some variabes that have application scope?
|
| kjak Wednesday, January 09, 2008 2:17 PM |
Yes, declare a static variable in your main cs(for C#) file, usually it is Program.cs in VS2005:
Code Block
namespace YourApp
{
static class Program
{
public static intmyInt = 0;
.
.
.
}
}
You can access it anywhere from your program by using Program.myInt
Regards,
Fábio
|
| Fábio Franco Wednesday, January 09, 2008 2:29 PM |
Code Block NamespaceYourApp
ClassProgram
PublicSharedmyIntAsInteger=0 EndClass EndNamespace
|
| Fábio Franco Wednesday, January 09, 2008 3:38 PM |
Yes, declare a static variable in your main cs(for C#) file, usually it is Program.cs in VS2005:
Code Block
namespace YourApp
{
static class Program
{
public static intmyInt = 0;
.
.
.
}
}
You can access it anywhere from your program by using Program.myInt
Regards,
Fábio
|
| Fábio Franco Wednesday, January 09, 2008 2:29 PM |
I am using VB.NET. Is there an equivalent to that in vb?
|
| kjak Wednesday, January 09, 2008 2:49 PM |
Code Block NamespaceYourApp
ClassProgram
PublicSharedmyIntAsInteger=0 EndClass EndNamespace
|
| Fábio Franco Wednesday, January 09, 2008 3:38 PM |
That was easy. Thank you!
|
| kjak Wednesday, January 09, 2008 3:59 PM |
Glad to be of help
|
| Fábio Franco Wednesday, January 09, 2008 4:38 PM |
I just want to add that you can make static/Shared variables anywhere, not just the "Program" file. They remain effectively "global", but it can help with organization 
-Ryan / Kardax
|
| Ryan Lamansky Wednesday, January 09, 2008 5:26 PM |
Yes Ryan, nice of you to pointed that out. I stated Program because that is the way I use it, that is the way I got used to when trying to be organized, but it is a good point. You can do it anywhere. |
| Fábio Franco Wednesday, January 09, 2008 5:44 PM |