?
Solved

using .vb files to hold variables

Posted on 2007-10-02
9
Medium Priority
?
177 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.
0
Comment
Question by:david_evans_work
  • 6
  • 2
9 Comments
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19996987
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
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19996991
In VB.Net

Public NotInheritable Class GloabalVariables
   
    Public Shared Globalint As Integer = 0
    Public Shared Globalstr As String = "Udhay"  
   
End Class
0
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19996998
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
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 

Author Comment

by:david_evans_work
ID: 19997025
I forgot to say i think I am using VB.net
0
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19997410
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 19997573
the nature of the web is to be stateless. between trips, you should persist your variables elsewhere. You can use cookies, session, viewstate, ....
0
 

Author Comment

by:david_evans_work
ID: 19997695
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
 
LVL 11

Expert Comment

by:udhayakumard
ID: 19997738
use the class and namespace
0
 
LVL 11

Accepted Solution

by:
udhayakumard earned 200 total points
ID: 19997743
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question