开发者

Is Variable Variable Possible?

开发者 https://www.devze.com 2023-02-06 20:43 出处:网络
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.

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 v开发者_如何学JAVAariable 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?


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


Well you can ... sort of.

By manipulating the VBE you may add lines to your program, so defining variables as you want. Of course this is not a straightforward way, nor I recommend it. It's just for your info.

Here is a tutorial.

More examples can be found googling "VBE insertlines"

HTH!

0

精彩评论

暂无评论...
验证码 换一张
取 消