Is it possible to use something like variable(nameOfVariable) = myValue
What I'm doing :
On of my XLA Add-In macro uses a lot of module-level variables ; many being Public and 256 being Const. Part of the Public ones are some pseudo-Const being udpated once in a while from the content of a (network-accessible) config.init file.
I thus need to assign value to a bunch of Public variables, at the start of the macro or when the user launches some specific procedures.
The content of the config.init file is very simple :
nameOfVariable1,value1
nameOfVariable2,value2
nameOfVariable3,value3
...
I'm currently setting theses variables using this Initialisation procedure :
Do While Not EOF(1) ' Loop until end of config.init
Line Input #fnum, TextLine ' Read line into variable Textline
myNameOfVariable = Split(TextLine, ",")(0)
Select Case myNameOfVariable
Case "nameOfVariable1"
nameOfVariable1 = Split(TextLine, ",")(1)
Case "nameOfVariable2"
nameOfVariable2 = Split(TextLine, ",")(1)
Case "nameOfVariable3"
nameOfVariable3 = Split(TextLine, ",")(1)
...
Loop
But this means I need to list every nameOfVariable in the Select Case statement of that procedure, even if the instruction assigning the value is stricly identical (= Split(TextLine, ",")(1)).
I'd like to replace the Select Case statement with something like :
Do While Not EOF(1) ' Loop until end of config.init
Line Input #fnum, TextLine ' Read line into variable.
nameOfVariable = Split(TextLine, ",")(0)
If thisvariableexist(nameOfVariable) then
variable(nameOfVariable) = Split(TextLine, ",")(1)
End if
Loop
so that I don't ever need to modify anything if I choose to add a new variable in the init file (new one or one currently declared as a Const).
Is it possible in VBA ?
