Global variables in .net 2.0 dont really exist the way they used to in C++ for example, because you dont have a single instance class running. If you are in the ASP.NET model, you can use the global.asax file to declare a Public or Public Shared variable,
or you can use Sessions as your global variable holder.
If you are in a VB model for win forms, Your best bet is to declare a class, and put a public member in it that will hold your value, and instanciate it when the application starts.
Application["varname"] = "sample!"
or craete a simple class like this
Public Class Sample1
Public Shared varname As String = "hi "
End Class
then call Sample1.varname
or
create class ---
Public NotInheritable Class [Global]
Private Sub New()
End Sub
Shared _importantData As String
Public Shared Property ImportantData() As String
Get
Return _importantData
End Get
Set
_importantData = value
End Set
End Property
End Class
u can set and we can get adata also
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Smadhu
Member
510 Points
985 Posts
how to declare global variable in page in vb.net
Mar 01, 2012 05:39 AM|LINK
how to declare global variable in page in vb.net
Dim Counter As integer
urenjoy
Star
12255 Points
1841 Posts
Re: how to declare global variable in page in vb.net
Mar 01, 2012 05:42 AM|LINK
Use the Session or Application objects, if you need such a "global".
Use Session if needed per user,Application if for the whole application.
</div>salman beher...
All-Star
30649 Points
5852 Posts
Re: how to declare global variable in page in vb.net
Mar 01, 2012 05:42 AM|LINK
Hi,
Global variables in .net 2.0 dont really exist the way they used to in C++ for example, because you dont have a single instance class running. If you are in the ASP.NET model, you can use the global.asax file to declare a Public or Public Shared variable, or you can use Sessions as your global variable holder.
If you are in a VB model for win forms, Your best bet is to declare a class, and put a public member in it that will hold your value, and instanciate it when the application starts.
refer also:http://stackoverflow.com/questions/4508606/global-variable-in-asp-net-website
Sincerely,
Salman
rohitpundlik
Contributor
3102 Points
934 Posts
Re: how to declare global variable in page in vb.net
Mar 01, 2012 05:43 AM|LINK
In VB.NET we have module to declare global variable, which can be accessed across all the forms
Module Module1
Public moduleinteger As Integer
End Module
Rohit Pundlik
Please mark as answer if this helps you...
Smadhu
Member
510 Points
985 Posts
Re: how to declare global variable in page in vb.net
Mar 01, 2012 05:48 AM|LINK
i want to delcare only 1 varaible on 1 page as global
can u please help me wid the code
rohitpundlik
Contributor
3102 Points
934 Posts
Re: how to declare global variable in page in vb.net
Mar 01, 2012 05:55 AM|LINK
you can declare it as a Static variable and use it...
Rohit Pundlik
Please mark as answer if this helps you...
Smadhu
Member
510 Points
985 Posts
Re: how to declare global variable in page in vb.net
Mar 01, 2012 06:00 AM|LINK
i have to declare varaible in backend code and has to use in front end code
public Counter as integer
will this work as global
venkatmca008
Participant
1810 Points
341 Posts
Re: how to declare global variable in page in vb.net
Mar 01, 2012 06:04 AM|LINK
hi...u can put this and use it any whare in apps
Application["varname"] = "sample!" or craete a simple class like this Public Class Sample1 Public Shared varname As String = "hi " End Class then call Sample1.varname or create class --- Public NotInheritable Class [Global] Private Sub New() End Sub Shared _importantData As String Public Shared Property ImportantData() As String Get Return _importantData End Get Set _importantData = value End Set End Property End Class u can set and we can get adata alsoMicrosoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com