Search code examples
phpvbavariablesvariable-variables

Is Variable Variable Possible?


My googlefu has failed me and I come to you for help:

Is VBA capable of having Variable Variables like PHP? I know that in PHP you can wait to declare a variable by using $$var.

Is it possible to do it in VBA? for example, is there a way that lets say: I read an entire array of 1000 strings and each string that I get can declare a variable with that string, e.g if the 80th element of an array is named STO how can I tell VBA to create a variable with the name sto?


Solution

  • It's not possible. But almost any code which relies on variable variables is horribly broken anyway and should be refactored e.g. to use array.

    Edit (pst): If you need to access values by a given name a dictionary can be used. An excerpt/example:

    Dim d As dictionary
    Set d = New dictionary
    d("STO") = arr(80) 'or whatever it is in VBA