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>
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>