Thursday, July 14, 2011

How to Declare and Use Global Static Variable in VB .Net

Generally you can not declare a static and global variable in VB.Net. You ned to declare them as Static in a Function or Subroutine, but declared variable in this way will not be available publically for further use.

Way To declare Globally a Static type variable :

In VB.Net we have a keyword named as ‘Module’, with the help of this keyword we can declare a static variable globally.

Code Systex :

Module Identifier
            Public Variable_Name As DataType
            ‘Optioanlly you can create object of this variable also. like
            Variable_Name = New DataType
End Module

·        It is not a class level variable, it should be file level.
·        You need to write this code outside your class.
·        It will be accessible in complete file.

Example :

Module myNewModule
            Public myDataSet As DataSet
            myDataSet = new DataSet
End Module

Way to Use :
·        You can use this variable as a simple normal global variable in any function or subroutine
·        It will be accessible in complete file.
·        You can update its value anywhere in the same file.
·        You can access its value anywhere in same file.

For any questions feel free to comment….

My Projects

  • J2EE Online entertainment world(fully running)

My Blog List