How Can I declare a variable in a sub that all subs can use?
Printable View
How Can I declare a variable in a sub that all subs can use?
You can create a class-level variable by declaring your variable outside of any methods, at the top of your class definition.
That won't work because I need to load the value of the variable from a file.
?? why not?
Just Declare the variable outside of all subs (at the top)
then set the variable when needed?
Dim X as integer
.
.
.
.
X = whatever from your file
Initialize the variable in the constructor.
Declare it as a module level variable, just below the Windows Form Designer generated code.
examples.
For a module or Class level variable:
Private msinNumOne as Single
Private mbln As Boolean
Private mdblTotal As Double
For Procedure Level Variables:
Dim psinNumOne as Single
Dim pbln As Boolean
Dim pdblTotal As Double
Hopefully, this helps you.
:D
I was going to make it a constant but I guess that dons't really mater.Quote:
Originally posted by [LGS]Static
?? why not?
Just Declare the variable outside of all subs (at the top)
then set the variable when needed?
Dim X as integer
.
.
.
.
X = whatever from your file