We help IT Professionals succeed at work.

using .vb files to hold variables

194 Views
Last Modified: 2013-11-26
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.
Comment
Watch Question

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
In VB.Net

Public NotInheritable Class GloabalVariables
   
    Public Shared Globalint As Integer = 0
    Public Shared Globalstr As String = "Udhay"  
   
End Class
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

Author

Commented:
I forgot to say i think I am using VB.net
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
√Čric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
the nature of the web is to be stateless. between trips, you should persist your variables elsewhere. You can use cookies, session, viewstate, ....

Author

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.


use the class and namespace
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.