%@ LANGUAGE="VBSCRIPT" %> <% Option Explicit '############################################################################## '## Module: Dealer CMS Finance calculators ## '## Version info: 1.0.0 ## '## Build date: 3:47pm Wed 20th Nov 2002 ## '## Copyright (C) 2002 T-Bone Productions ## '## ## '## Contact: http://www.t-bone.com.au ## '############################################################################## %><% dim cmdSubmit, MonthlyTermPayment dim LoanAmount, InterestRate, Years, PaymentsPerYear dim blnErr, strMsg, eobj '#### CONSTANTS AND INTIALISATION ################################### cmdSubmit = request("cmdSubmit") blnErr = FALSE PaymentsPerYear = 12 '# Intialise our error dictionary object set eobj = CreateObject("Scripting.Dictionary") eobj.Add "msg", "There were errors in your form, please see fields marked with *." '#### PAGE LOGIC #################################################### if cmdSubmit = "Calculate" then GetFormData() ErrorCheck() if blnErr then strMsg = GetErrors(eobj) else MonthlyTermPayment = CalculateLoanPayment(LoanAmount, InterestRate, 0, Years, PaymentsPerYear) end if end if '#### FUNCTIONS ##################################################### Sub GetFormData() loanamount = CLong(request("loanamount")) InterestRate = CLong(request("interestrate")) Years = CLong(request("years")) End Sub Sub ErrorCheck() if (LoanAmount < 10000 OR LoanAmount > 1000000) then eobj.Add "loanamount", strArw & "The loan amount must be between $10,000 and $1,000,000" if (InterestRate < 1 OR InterestRate > 51) then eobj.Add "interestrate", strArw & "The interest rate must be between 1% and 51%" '# raise our error flag if we have error to report if eobj.Count > 1 then blnErr = TRUE End Sub '# From toyota's Spreadsheet: Arrear's monthly payment no balloon Function CalculateLoanPayment(ByRef Amount, ByRef InterestRate, ByRef ResidualValue, ByRef Years, ByRef PaymentsPerYear) dim i, arr, answer, NumberOfPayments, dollars, cents NumberOfPayments = Years * PaymentsPerYear i = InterestRate/100/12 answer = (Amount -(ResidualValue*(1+i)^-NumberOfPayments))/((1-(1+i)^-(NumberOfPayments))/i) arr = split(answer, ".") dollars = arr(0) cents = left(arr(1), 2) CalculateLoanPayment = dollars & "." & cents End Function '####################################################################%>