Best Practice for Global Variables
I'm writing my first VB.NET application. It's a very simple application that only has 1 form.
A variable that I am declaring needs to be used in multiple procedures (2 button events to be exact). Therefore, I know that I need to declare the variable outside of the button procedure so that it is accessible by both procedures. The question is what's the best way:
Option A) Declare the variable within the form class:
Class Form
Dim MyVar
Procedure A
Do Something
End Procedure A
Procedure B
Do Something
End Procedure B
End Class Form
Option B) Declare the variable within a module that is within the same source file as the form class:
Class Form
Procedure A
Do Something
End Procedure A
Procedure B
Do Something
End Procedure B
End Class Form
Module 'This module in the same source file as the Form
Dim MyVar
End Module
Option C) Declare the variable within a seperate module
Class Form
Procedure A
Do Something
End Procedure A
Procedure B
Do Something
End Procedure B
End Class Form
Module 'This module in a seperate source file (module1.vb)
Dim MyVar
End Module

