Sorry in advance, I'm a self-taught VBA programmer, and I'm not sure how to phrase my question! I've declared constants which have similar names, i.e.
Public Const BP1Enable = "something1something:someotherthing1someotherthing"
public const BP2Enable = "something2something:someotherthing2someotherthing"
etc.
I have 10 of these constants. I have a sub with these constants as arguments:
Sub FieldEnable (ByVal enableconst)
Now I want to call the FieldEnable sub in a loop using i as counter:
For i = 1 To 10
BPfieldname = "BP" & i & "Enable"
FieldEnable enableconst:=BPfieldname
Next i
This does not work, what is happening is that the "value" assigned to enableconst in the sub FieldEnable, is "BP1Enable" instead of the value of the constant BP1Enable namely "something1something:someotherthing1someotherthing".
How can I use the variable BPfieldname when calling the sub FieldEnable?
I hope this makes sense. Any help appreciated.
Also, if you are going to be using this "constant" in more than one place, more than one function, you can effectively make an array constant, that can even be called that way.
Immediate Window:
Transform your variables into a single Array.
See this http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx
EDIT: as @sina has correctly pointed out, VBA does not allow constant arrays,
so instead of trying this
you should try this
The best guess would be to use a constant array, but constant arrays are not supported by VBA.
Therefore you could go with building an array out of your constants before you start your loop:
Another option would be to declare all constants as one long string with some defined separator and use a split function on that string to generate the array.