Solved How to use Power operator in VBA?

deletedT

Guest
Local time
Today, 00:05
Joined
Feb 2, 2019
Messages
1,218
I feel being stupid to ask this, but how can I use power operator in vba?

myVar = (Ele/2^4) Mod 2
gives me Expected: ) error.

myVar = 2^4
Shows the same error too.


thanks.
 
What do you get with this in the Immediate Window?

?2^4
 
Not sure, this just worked fine:

Code:
Dim myVar As Long
myVar = 2 ^ 4
Debug.Print myVar
 
I think I got the point.
It seems in vba 2^2 is different with 2 ^ 2

So I must add the space manually. 2+2 will be changed to 2 + 2 as soon as I move to another line.
But 2^2 throws the error until the space is added manually.


Thanks for your help.
 
I have 32bit. I've got a VM with 64bit I can fire up if you need it tested there. Funny as I copy/pasted your line of code and the spaces got added automatically. I tried taking them out and as soon as I left the line they returned.
 
As you see, I'm in the next line, but the spaces are not there.

2020-06-24_11-05-20.jpg
 
Last edited:
Glad you got it sorted.
 

Users who are viewing this thread

Back
Top Bottom