For example, if I have the array:
DeviceArray = Array("Sw","Cap","Gen","Reg","Tr","Br")
And I want to initialize everything to a value such as 0, what would be the equivalent to writing a for loop for this such that the value within the array is treated as a variable name instead so that I can indirectly modify variable values:
For i = 0 to ubound(DeviceArray)
DeviceArray(i) = 0
Next i
Such that after running the code, the variables: Sw, Cap, Gen, Reg, Tr, and Br should all be set to 0.
Versus every element in DeviceArray being changed to 0 and no longer storing the strings initially placed.
So DeviceArray should remain unchanged and still store the values ("Sw","Cap","Gen","Reg","Tr","Br")
Hope that clearly explains what I am trying to do, I am attempting to do this so I do not have to type:
Sw = 0
Cap = 0
Gen = 0
Reg = 0
Tr = 0
Br = 0
Because there is a long list of variables that need to be constantly reinitialized to different values throughout my macro.
So for example DeviceArray(0) = Sw
, but I want the VBA macro to recognize DeviceArray(0)
as the name of a variable Sw
instead such that I can modify the value of the variable Sw
without calling it directly.