Click to See Complete Forum and Search --> : Exponent function please help im sure its easy


mcmcom
November 21st, 2003, 04:41 PM
Hi all,

I am making a simple compound interest calculator. I need to know how to do exponents in vbscript. I know in Java its Math.Pow(x,y) where x is raised to the yth power. Problem is in vbscript there is only EXP(x) where x is raised to a power, but how do i spec the power. As you can see the formula that is needed is basically:

principal * (1.0+rate to the power of YEARS) How can I do this in VBscript because I can't use EXP(1.0+rate,years) because it only takes one argument. PLEASE HELP THANKS

this is the script:

<script type = "text/vbscript">
<!--
Option Explicit

dim x
dim amount
amount = 1

Public Function CalcInterest(principal, rate, years)



Do while x < years
amount = amount + principal * Exp(1.0 + rate)
x = x + 1
loop

document.forms (0).fldTotal.value = amount


End Function

Sub cmdCalculate_OnClick()
Dim p, r, y

'convert each input to long
p = CLng( Document.Forms (0).Principal.Value )
r = CLng( Document.Forms (0).InterestRate.Value )
y = CLng( Document.Forms (0).Years.Value )

Call CalcInterest(p,r,y)

End Sub
-->
</script>

Satishpp
November 21st, 2003, 04:55 PM
Exponentiation
usage is:

(numeric variable or constant) ^ (numeric variable or constant)

raises first value to the power of the second value
e.g., fred=4 ^ 3
returns 64
e.g., fred=3 ^ 2
returns 9