realbasicxojorealstudio

Get value of variable named in a string


Is there any way to get the value of a variable that has been named in a string. For instance:

Dim number As Integer = 12

Dim numberCopy As Integer = Convert("number")
' numberCopy will now equal 12
' Convert is the function to convert the string to the variable

Solution

  • Something like that can be done only with Introspection, and only if the variable holding the value is a property of a class. Your example, where the variable is only temporarily known inside a function, cannot be made work as you like.

    To learn more about Introspection, see the documentation and examples of the same name.