Passing a value to a global variable RRS feed

  • Question

  • User-1312727929 posted

    Can I pass an external value to a global variable in a class? Right now, I do it like this:

    Public Class myClass
    Dim myGlobalVar as string
    Public Function myFunction(myVar as string)
    End Function
    End Class

    As you see, I am using two variables, and assign the value of the local variable to the global variable in the function. I wonder if you can do this more efficient, i.e. using only one variable.

    Monday, January 18, 2016 4:53 PM


  • User-2057865890 posted

    Hi esims,

    You could create a class with shared properties:

    Public Class GlobalVariables   
       Public Shared Property MyGlobalString As String
    End Class

    Access the global variables

    GlobalVariables.MyGlobalString = "Test"

    Best Regards,

    Chris Zhao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2016 8:09 AM