VB.NET - where do i suppose to declare a Global variable?

Asked By Ralph Acido on 04-Apr-06 10:52 PM
hello! i want o declare a global variable in my Application so that i can access this to all my forms.. anyone who can help me?

where do i suppose to declare a Global variable - Asked By John Conway on 04-Apr-06 11:06 PM

Declare your variable in a Module

continued - Asked By John Conway on 04-Apr-06 11:15 PM

Use:

Private for Module level Scope 
Friend for Project level Scope
Public for Solution level Scope

Containers - Asked By Ramya T on 04-Apr-06 11:27 PM

[CODE]

Imports System.Collections
    Public Class StaticContainer
        Private Shared thing As Hashtable
        Public Shared Sub InitThing()
            thing = New Hashtable()
        End Sub
        Public Shared Sub KillThing()
            thing.Clear()
            thing = Nothing
        End Sub
        Public Shared Sub AddContainer(ByVal key As Object)
            thing.Add(key, New ArrayList())
        End Sub
        Public Shared Sub RemoveContainer(ByVal key As Object)
            thing.Remove(key)
        End Sub
        Public Shared Sub AddToContainer(ByVal newname As String, ByVal index As Integer, 
        ByVal stuff As String, ByVal key As Object)
            Dim temp As ArrayList = thing.Item(key)
            thing.Remove(key)
            Dim t As New triple()
            t.name = newname
            t.ID = index
            t.data = stuff
            temp.Add(t)
            thing.Add(key, temp)
        End Sub
        Public Shared Function GetEntry(ByVal x As Integer, ByVal key As Object) As triple
            Dim temp As ArrayList = thing.Item(key)
            Dim result As triple
            If temp.Count > x And x >= 0 Then
                result = CType(temp(x), triple)
            End If
            Return result
        End Function
    End Class
    Public Structure triple
        Public name As String
        Public ID As Integer
        Public data As String
    End Structure

[/CODE]


In global.asax 


[CODE]

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application is started
        StaticContainer.InitThing()
    End Sub
    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session is started
        Session.Add("key", DateTime.Now.Ticks.ToString("x"))
        StaticContainer.AddContainer(Session.Item("key"))
    End Sub
    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session ends
        StaticContainer.RemoveContainer(Session.Item("key"))
    End Sub
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application ends
        StaticContainer.KillThing()
    End Sub


[/CODE]


CHECK THIS LINK FOR MORE EXPLAINATION

http://www.dotnetjunkies.com/Tutorial/FA28D27E-82ED-4B91-96E4-65C97F6B6DBE.dcik
one option is modules - Asked By Venkat K on 05-Apr-06 12:08 AM
Add a module to your project, and declared Global variables there, like this:

Module Variables
  Public Response As String = "Hello World"
End Module
declare ur variable as public - Asked By Amit Khurana on 05-Apr-06 06:12 AM
declare ur variable ..public in ur module..

thxz
where do i suppose to declare a Global variable? - Asked By Sukanta Kumar Mohapatra on 05-May-06 03:16 AM
where do i suppose to declare a Global variable?