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
Module Identifier
Public Variable_Name As DataType
‘Optioanlly you can create object of this variable also. like
Variable_Name = New DataType
End Module
NOTE :
· 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….