N1 = 3
N2 = 4
N3 = Sqr(N1^(2) + N2^(2)) 'N3 is the hypotenuse
MsgBox N3
I get the following error and N1^
is highlight.
N1 = 3
N2 = 4
N3 = Sqr(N1^(2) + N2^(2)) 'N3 is the hypotenuse
MsgBox N3
I get the following error and N1^
is highlight.
There seems to be some issues with the power operator, please refer to this thread:
VBA power operator (^) not working as expected in 64-bit VBA
Also temporary fix to this issue mentioned in this thread, use the below function to calculate power:
Excel.WorksheetFunction.Power(N1, 2)
Edit: for Powerpoint VBA, I'm not sure if there's a library function that would calculate the power, but for integer type of power number, we can simply wrap a loop into a function:
Public Function myPower(base As Double, pow As Long) As Double
Dim ret As Double: ret = 1
If pow > 0 Then
For i = 1 To pow
ret = ret * base
Next i
Else
For i = -1 To pow Step -1
ret = ret / base
Next i
End If
myPower = ret
End Function
For floating point power number... I'll have to go back and check the formula....
Second Edit: I just tested putting parenthesis on the variables then using caret, seems to be working on my 64bit Excel, maybe you should try this in PowerPoint first :)
Public Sub test()
N1 = 3
N2 = 4
N3 = Sqr((N1) ^ 2 + (N2) ^ 2)
MsgBox N3
End Sub