Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring global, static variables

I'm trying to set a global variable in Visual Studio, but I can't make it static. Is there any way for me to set the variable as static and share it across different methods, or some way to save the variable each time it changes?

like image 245
user3568182 Avatar asked Sep 02 '26 19:09

user3568182


1 Answers

You have two options:

1 - Create a class that contains a Shared variable (this is the same as a static variable in C#)

    Public Class GlobalVariables
        Public Shared Bar As String
    End Class

You can then access this using the class name:

GlobalVariables.Bar = "Hello world"

2 - Create a module (this is akin to a static class in C#)

    Public Module GlobalVariables
        Public Bar As String
    End Module

You can then access this value in code like this:

Bar = "Goodbye cruel world"
like image 199
Matt Wilko Avatar answered Sep 05 '26 16:09

Matt Wilko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!