Click to See Complete Forum and Search --> : Problems with stupid vbScript


mcmcom
November 20th, 2003, 03:24 PM
Below is a snippet of code im writing for a simple interest calculator. The problem with it is the For Loop can someone show me how to do it right, Its not looping. I know how to do it in javascript with the :

for(x=0;x<years;++x)

But I have to do this in VBScript and I have NO EXAMPLES OF How to do it. Any help would be appreciated.


<title>Compound Interest Calculator</title>

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

dim x
dim amount


Public Function CalcInterest(principal, rate, years)

RIGHT HERE IS WHERE IT SCREWS UP!
For x = 0 to x < years
amount = principal * Math.pow(1.0 + rate, year)
x = x+1
window.alert(amount)
Next

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

THANKS IN ADVANCE!!!! MIKE

Thread1
November 24th, 2003, 02:48 AM
For x = 0 to x < years --> For x = 0 to years-1