可变变量可能吗? [英] Is Variable Variable Possible?

查看:69
本文介绍了可变变量可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的googlefu让我失败了,我来向您寻求帮助:

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

VBA是否可以像PHP一样具有变量变量?我知道在PHP中,您可以等待使用$$var声明变量.

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

是否可以在VBA中进行?例如,有一种方法可以说:我读取了1000个字符串的整个数组,并且我得到的每个字符串都可以使用该字符串声明一个变量,例如,如果数组的第80个元素命名为STO,如何告诉VBA创建一个名为sto的变量?

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?

推荐答案

这是不可能的.但是几乎所有依赖于变量的代码都被可怕地破坏了并且应该被重构,例如使用数组.

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.

编辑(pst): 如果您需要使用给定名称访问值可以使用字典.摘录/示例:

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

这篇关于可变变量可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆