using .vb files to hold variables

Hope you can help, i am pretty new to asp.net vb. i have created a file in my app_code folder called config.vb and want to set some global variables that can be used across all the pages in the whole application, my question is, how do i set the variables in the .vb file and how do i make them accessible to the pages and how do i call the variable value.
david_evans_workAsked:
Who is Participating?
 
udhayakumardConnect With a Mentor Commented:
Suppose

NameSpace Test

   Public NotInheritable Class GlobalVariables
   
       Public Shared imgurlstr As String = "http://images.com/"
   
   End Class

End NameSpace

then use it as


Label1.Text = Test.GlobalVariables.imgurlstr

0
 
udhayakumardCommented:
put all the global variables in a static class and make all the variables as Public

Ex:

public static class GloabalVariables
{
          public static int Globalint = 0;
          public static string GLobalstr = "Udhay";


}

Else make use of Property
0
 
udhayakumardCommented:
In VB.Net

Public NotInheritable Class GloabalVariables
   
    Public Shared Globalint As Integer = 0
    Public Shared Globalstr As String = "Udhay"  
   
End Class
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
udhayakumardCommented:
You can access this variable from other files in the following way

a = GloabalVariables.Globalint


make sure that the namespace of all the files are same

if namespaces are different then

a = {namepsace}.GloabalVariables.Globalint
0
 
david_evans_workAuthor Commented:
I forgot to say i think I am using VB.net
0
 
udhayakumardCommented:
Still you can use that

In VB.Net

Public NotInheritable Class GloabalVariables
   
    Public Shared Globalint As Integer = 0
    Public Shared Globalstr As String = "Udhay"  
   
End Class
0
 
Éric MoreauSenior .Net ConsultantCommented:
the nature of the web is to be stateless. between trips, you should persist your variables elsewhere. You can use cookies, session, viewstate, ....
0
 
david_evans_workAuthor Commented:
my idea was that i place a global variable into my globalvariables.vb file like this:
Public Shared imgurlstr As String = "http://images.com/"
which is fine, but on my other page example.aspx.vb i want to put, as an example:  
Label1.Text = imgurlstr

but it just says imgurlstr is not declared, i want it to read the value from the .vb file

Or is this not the right thing to be doing, i didn't really want ot be going down the cookie or session route.


0
 
udhayakumardCommented:
use the class and namespace
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.