Showing posts with label Visual Basic. Show all posts
Showing posts with label Visual Basic. Show all posts

March 27, 2019

How to Create Global Variables In Visual Basic

Today's post is a quick one, brought about by necessity when I was doing my programming homework this afternoon. In order to do my assignment, I had to use VB's variant of Global Variables, which, it turns out, is a major pain in the... you get the idea. This brief tutorial is specific to Visual Studio 2017, as that is the compiler that I use for Visual Basic.


  • Right Click on the solution name in Solution Explorer
  • Select Add > Module

  • Name the module with reference to the project name as you might be making a lot of these.

  • Write Module like so
       Module /modulename/

          'Global Variables for use throughout the program
           Public Var1 As Type
           Public Var2 As Type
           Public Var3 As Type
           'etc...

       End Module


  • Save Module
  • Use variables throughout the program