预先抱歉,我是一名自学成才的VBA程序员,而且不确定如何表达我的问题!我已经声明了具有相似名称的常量,即
Public Const BP1Enable = "something1something:someotherthing1someotherthing"
public const BP2Enable = "something2something:someotherthing2someotherthing"
等等。
我有10个这些常数。我有一个用这些常量作为参数的子:
Sub FieldEnable (ByVal enableconst)
现在,我想使用i作为计数器在一个循环中调用FieldEnable子:
For i = 1 To 10
BPfieldname = "BP" & i & "Enable"
FieldEnable enableconst:=BPfieldname
Next i
这不起作用,正在发生的是分配给子FieldEnable中的enableconst的“值”是“ BP1Enable”,而不是常量BP1Enable的值“ something1something:someotherthing1someotherthing”。
调用子FieldEnable时如何使用变量BPfieldname?
我希望这是有道理的。任何帮助表示赞赏。
将变量转换为单个数组。
看到这个http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx
编辑:正如@sina正确指出的那样,VBA不允许常量数组,
所以不要尝试这个
Dim BPEnable = {
"something1something:someotherthing1someotherthing",
"something2something:someotherthing2someotherthing",
....
}
你应该试试这个
Dim BPEnable
BPEnable = Array( _
"something1something:someotherthing1someotherthing", _
"something2something:someotherthing2someotherthing", _
"..."
)
For i = 0 To UBound(BPEnable)
BPfieldname = BPEnable(i)
Next i
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句