Let me show you what I am doing with simpler named variables (it will be
easier to follow). Let's say a variable can only have two possible value.. 5
and 9 (just to pick two numbers at random). To match what is going on in my
code, let's use constants to hold these values... say A=5 and B=9. Now
consider a variable (named V for this example) that you want to toggle back
and forth between the value in A and the value in B. My code line does
this...
V = A + B - V
So, if the current condition is V=A, executing the above line will set V
equal to B (we are subtracting A from A+B leaving B). Execute the line again
and V will become A again (now, we are subtracting B from A+B leaving A),
and so forth. Each time the code line is executed, it toggles V back and
forth between A and B. So, the equivalence between my previously posted code
and the code line above is this....
V = Application.Calculation
A = xlCalculationAutomatic
B = xlCalculationManual
Now, for this to work, V must be initialized with one of the values A or B.
We can do that in code, if necessary, but in the case of the calculation
mode, the "variable" Application.Calculation is already pre-initialized for
us and the constants xlCalculationManual and xlCalculationAutomatic are
predefined by VBA.
Rick
> I'm not sure if I should ask these questions here or start a new
> thread.
>
> However, I'm curious about the syntax.
>
> I notice your use of + and -.
>
> I've never seen that before.
>
> Please describe what that does.
> Is that convention useful only for constants?
>>
>> Private Sub CommandButton1_Click()
>> Application.Calculation = xlCalculationAutomatic + _
>> xlCalculationManual - _
>> Application.Calculation
>> CommandButton1.Caption = IIf(Application.Calculation = _
>> xlCalculationManual, "MANUAL", "AUTO")
>> End Sub
|