Groups | Blog | Home
all groups > dotnet faqs > november 2003 >

dotnet faqs : global variables in .NET: how to store a connection string and have it available throughout..


chris
11/25/2003 6:45:07 PM
There's a simple answer I'm sure, but it's eluding me. If I want to declare
a variable and then initialize it in module A, then have it's initialized
value available in module B without passing it as an argument, how to do?

Thanks,
Chris

Miha Markic
11/26/2003 12:01:59 PM
Hi chris,

VB.NET:
Module Module2

Public AValue As String = "Tubo"

End Module

Use: Dim s as string = Module2.AValue



C#:

public class Tubo

{

public static string AValue = "Tubo";

}

Use: string s = Tubo.AValue;


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

[quoted text, click to view]

Troy
12/4/2003 6:32:28 PM
I tried this solution in storing the user's login name. The first .aspx file shows the initial value of the login name variable declared inside the module and prompts the user to enter his own login name . how come when I run the application in VS.NET again, the same login name last inputted shows up, it's like the module doesn't reset it's own value.

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Miha Markic
12/5/2003 10:54:22 AM
Hi Troy,

You should say that you are on the asp.net :)
Store it in the either Session collection (Session["key"] = value) or
Application collection (Application["key"] = value) .

--
Miha Markic - DXSquad/RightHand .NET consulting & software development
miha at rthand com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to support@devexpress.com
Bug reports should be directed to: support@devexpress.com
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.


[quoted text, click to view]
file shows the initial value of the login name variable declared inside the
module and prompts the user to enter his own login name . how come when I
run the application in VS.NET again, the same login name last inputted shows
up, it's like the module doesn't reset it's own value.
[quoted text, click to view]
ASP.NET resources...

AddThis Social Bookmark Button