Global Variables in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the global variables in Visual Basic .NET

A global variable is a variable with global scope, and unlike the local variable can be accessed from anywhere.

Meaning when the variable is available globally, any code in your application has access to read and modify this variable.

For storing global variables in VB.NET you "usually" have a Module because it's static and doesn't have to be instantiated.

Module GlobalVariables
    ' sets the Form's text property (title)
    Public global_FormText As String = "Hello World!"
End Module                  

Then you can call global_FormText like so:
Me.Text = global_FormText    
' or    
Me.Text = GlobalVariables.global_FormText   

Previous Lesson | Next Lesson

Share This

Home | About | Contact | Privacy Policy

Copyright 2018 - All Rights Reserved.