Wrox Programmer Forums Investment calculator - help
 |
 Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
 Welcome to the p2p.wrox.com Forums. You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

October 1st, 2004, 02:21 PM
 activexcode Registered User Join Date: Oct 2004 Posts: 5 Thanks: 0 Thanked 0 Times in 0 Posts
Investment calculator - help

I'm coding an investment calculator in Microsoft Visual Studio 2003.
I need to show an initial investment of 200, with an expected annual rate of 8%, for six years, on the form.

How do I calculate on my asp page so that the form will generate the following calculation:

Year 1 \$216
Year 2 \$233.28
Year 3 \$251.9424
Year 4 \$272.097792
Year 5 \$293.86561536
Year 6 \$317.3748645888

Thanks so much. My email is activexcode@hotmail.com.

October 1st, 2004, 09:04 PM
 rajanikrishna Friend of Wrox Join Date: Sep 2003 Posts: 363 Thanks: 0 Thanked 1 Time in 1 Post

dim strYearAmt,i,iniAmt,yrAmt,arrAmt
iniAmt=200
yrAmt=iniAmt
for i=1 to 6
yrAmt=round((((yrAmt * 8)/100)+yrAmt),i)
strYearAmt=strYearAmt & yrAmt & ","
next

arrAmt=split(strYearAmt,",")

'generate the form

strFORM="<form name='frm1' action='mypage.asp' method='post'>"
for j=0 to ubound(arrAmt)-1
strFORM=strFORM & "<input type='text' name='txtYr' value='" & arrAmt(j) & "'>Year" & j+1 & "<br>"
next

response.write strFORM

I just displayed the values in 6 text boxes for 6 years.

------------
Rajani

October 2nd, 2004, 07:47 PM
 activexcode Registered User Join Date: Oct 2004 Posts: 5 Thanks: 0 Thanked 0 Times in 0 Posts

Sorry. I should've been clearer. I created an investment calculator in asp, designed to post as a form on the web. When it posts to the web, the user should be able to:

1)Put in ANY amount in the initial investment box (say, 200 as an example)

2)Put in ANY expected annual rate of return (say, 8% as an example)

3)Put in ANY number of years (say, 6 as an example)

Once they press the CALCULATE the FUTURE VALUE button, they should see a two-column table, underneath the form, which shows a running total:

Year 1 \$216
Year 2 \$233.28
Year 3 \$251.9424
Year 4 \$272.097792
Year 5 \$293.86561536
Year 6 \$317.3748645888

Here's my original code. It seems okay, except I can't get it to calculate from Year 1 on, as described above. And I'm having trouble creating the tw-column table. How do I incorporate your calcs into my current code? Please correct my syntax where necessary. Thanks for your help! :-}
__________________________________________________ ____
<%

DIM counter, initialinvestment, annualrateofreturn, numberofyears, investmentvalue

initialinvestment = request.form ("initial investment")
response.write ("Initial investment is:" & initialinvestment & "<br/>")

annualrateofreturn = request.form ("annual rate of return")
response.write ("Annual rate of return is:" & annualrateofreturn & "<br/>")
numberofyears = request.form ("number of years")
response.write ("Number of years:" & numberofyears & "<br/>")

investmentvalue = initialinvestment*(1 + annualrateofreturn)

for counter = 1 to numberofyears
response.write(counter&" " & "<br/>")
investmentvalue = initialinvestment*(1 + annualrateofreturn)
response.write (investmentvalue&" " &"<br/>")
next

%>
<form method = "post" action= "InvestmentCalc.asp">
<h3>Investment Calculator</h3>
<b>Initial Investment:</b
<input type= "text" name= "initial investment" value='<%= initialinvestment%>'/><br/>

<b>Expected Annual Rate of Return %:</b>
<input type="text" name="annual rate of return" size = "10" maxlength = "10" value="<%= annualrateofreturn%>"/><br/>

<b>Number of Years:</b>
<input type="text" name="number of years" size = "3" maxlength = "3" value="<% =numberofyears%>"/></p>

<input type="submit" value="Calculate the Future Value"/></p>

</form>

</body>

</html>

October 3rd, 2004, 04:34 AM
 happygv Friend of Wrox Join Date: Jun 2003 Posts: 2,480 Thanks: 0 Thanked 1 Time in 1 Post

Hi Activexcode,

Rajani has given the you the entire "working" code. There shouldn't much of diffucilty in incorporating that in your code. hmmm!

You got to comment this line and add the following line in blue next to the commented lines.
Code:
```'investmentvalue = initialinvestment*(1 + annualrateofreturn)
investmentvalue = initialinvestment```
Also replace your FOR...NEXT loop code with this one.
Code:
```for counter = 1 to numberofyears
'investmentvalue = initialinvestment*(1 + annualrateofreturn)
investmentvalue = round((((investmentvalue * annualrateofreturn)/100)+investmentvalue), (counter-1)*2)
response.write(counter& " ------ " & investmentvalue& " " &"<br>")
next```
The lines in GREEN above are the culprits in your code.

Hope that explains.

Also I am not sure why /> has been used in all the places where TAGs are used. Is that ASP.Net code, where the controls need to be closed with "/>"? I haven't seen that in use for classic ASP.

Cheers!

_________________________
- Vijay G
Strive for Perfection

October 3rd, 2004, 09:37 AM
 activexcode Registered User Join Date: Oct 2004 Posts: 5 Thanks: 0 Thanked 0 Times in 0 Posts

Yes. Asp.net.

October 3rd, 2004, 10:23 AM
 happygv Friend of Wrox Join Date: Jun 2003 Posts: 2,480 Thanks: 0 Thanked 1 Time in 1 Post

I would suggest you better submit that on an ASP.NET forum here in this site. This is a Classic ASP forum.

_________________________
- Vijay G
Strive for Perfection

 Similar Threads Thread Thread Starter Forum Replies Last Post calculator mojtaba rashidi Visual Studio 2005 0 March 17th, 2008 07:29 AM Affiliated Investment Group, Inc. Lease Other Programming Languages 1 March 13th, 2007 02:37 PM Calculator DweeLer Other Programming Languages 1 November 18th, 2005 08:13 AM calculator kale_tushar C++ Programming 1 January 28th, 2004 01:09 PM