views:

296

answers:

3

Here is some math code that adds A to B:

Sub math()
    A = 23
    B = 2
    ABSumTotal = A + B
    strMsg = "The answer is " & "$" & ABSumTotal & "."
    MsgBox strMsg
End Sub

But how can I calculate a square root of ABSumTotal? Is it possible in PowerPoint VBA?

+5  A: 

Use: Sqr()

strMsg = "The answer is " & "$" & Sqr(ABSumTotal) & "."
CodeMonkey
CodeMonkey
Thanks a lot!!!
brilliant
you're welcome.
CodeMonkey
+2  A: 

Have you tried the function Sqr?

See: http://msdn.microsoft.com/en-us/library/h2h9y284%28VS.85%29.aspx

Ben Gribaudo
+1  A: 

You can use use ^ to compute X^(1/2)

Edit: added parenthesis

RC
I would generally advise against ^ since it's less readable.
CodeMonkey
I misreaded the question and answered for cubic root and made a correction afterwards. But I dont think x^1/2 is less readable than sqr(x) which looks like square to much to me :)
RC
Doesn't exponentiation take precedence over division? If so, you'd need x^(1/2).
Dick Kusleika
@dkusleika, nice catch, thanks.
RC
(^) is usually slower too.
RBarryYoung