Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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
 
Old April 27th, 2008, 10:25 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default New to ASP.NET and lots of problems

Hi all,
I'm new to the forum and new to ASP.NET and having lots of problems. All the programming I've ever done has been in C and it's been a LONG time since I've done that. We took on a new project at work that uses ASP.NET 1.1 mixed with Visual Basic, so I'm taking a self study type course to get up to speed, and I can't even get the first example running. It's the good old Investment Calculator program where you enter the starting and ending amount and the rate of growth and tell how many years it takes to grow. I'm pasting my code below...I tried looking at several online tutorials and the Wrox Asp.Net 1.1 with VB.Net book and I don't see what I'm doing wrong. I don't even know if it's doing the calculations and it's certainly not printing the answer!
Apart from any suggestions on this program, if you have any suggestions of good "remedial" ASP.NET resources that I could look at I would really appreciate it. I'm so lost and I'm not sure where to begin.
-Lessa
--------------

<%@ Page Language="vb" runat="server" %>
<script runat="server">

    Sub Calculations()

      Dim dblInvestment As Double = CDbl(txtStartingInvestment.text)
         Dim dblFinalInvestment As Double = CDbl(txtEndingInvestment.text)
         Dim dblGrowth As Double = CDbl(txtGrowth.text)
         dim Years as integer=0

          do while dblInvestment < dblFinalInvestment
          dblInvestment = (dblInvestment * dblGrowth) + dblInvestment
          Years = Years + 1
             loop
      lblyears_result.text = CStr(Years)

    End Sub

</script>
<html>
<head>
</head>
<body>
    <h3>Investment Calculator
    </h3>
    <form runat="server">
        Please enter your initial investment: $
        <asp:TextBox id="txtStartingInvestment" runat="server" width="80px"></asp:TextBox>
        <br />
        Please enter your desired ending amount: $
        <asp:TextBox id="txtEndingInvestment" runat="server" width="80px"></asp:TextBox>
        <br />
        Please enter the percentage of growth (i.e. 0.08 for 8 percent)
        <asp:TextBox id="txtGrowth" runat="server" width="80px"></asp:TextBox>
        <br />
        <asp:button id="Button1" runat="server" text="Submit"></asp:button>

        <asp:Label id="lblyears_result" runat="server"></asp:Label>
        <br />
        <br />
    </form>
</body>
</html>


 
Old April 27th, 2008, 10:44 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It would appear that you are missing an event handler for the button. Your button may be causing a postback, however it will not trigger any event unless you tell it to do so. Try the following modifications:

   Sub Calculations(sender As Object, e As EventArgs)

   <asp:button id="Button1" runat="server" text="Submit" OnClick="Calculations"></asp:button>

-Peter
peterlanoie.blog
 
Old April 28th, 2008, 07:19 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay I changed the button like you said. I don't think I understood the Submit button very well to begin with...can't believe I forgot to tell it to DO something.

So now it does something...it's just wrong. No matter what numbers I use it prints the answer as zero. I'm thinking my problem is with the variables in my Calculations sub because I'm not sure if I converted them to doubles correctly. It seems like it should work when I step through it on paper which is why I say I suspect the variables.

Am I making this harder than it needs to be?

 
Old April 28th, 2008, 07:37 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm. A do while here is over kill, you could get by with a simple While:

While dblInvestment < dblFinalInvestment
    dblInvestment = (dblInvestment * dblGrowth) + dblInvestment
    Years = Years + 1
End While

Your logic seems fine though, as you guessed, I think the variables do not contain the values you think they do. Since you have indicated that you are a beginner I won't suggest dropping in a break point to step through the code, instead do something like this so you can see what the values are:

Response.Write("Starting Investment: " & Convert.ToString(dblInvestment) & "<br>")
Response.Write("Ending Investment: " & Convert.ToString(dblFinalInvestment) & "<br>")
Response.Write("Growth: " & Convert.ToString(dblGrowth))

Also, I am unaware of any caveate to using CDbl() but you may want to use Convert.ToDouble() just in case.

hth.
-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 28th, 2008, 08:03 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm...it gave me the right numbers back when I used that...which means that it's getting lost somewhere on incrementing years maybe? Maybe for simplicity's sake I should change it to the while loop like you suggested. The best example I found in the book was using a do while so that's why I went with that since I had a clear example to pattern it after.
Back to the drawing board.

 
Old April 28th, 2008, 08:12 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

A do while is a special purpose loop

Do
'Code
While (condition)
'more code could go here
Loop

The code that exsists between Do and While will execute at least 1 time regardless of what the condition in your while clause equates to.

Years should increment correctly based on the logic. Is dblInvestment less than dblFinalInvestment??

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 28th, 2008, 10:28 PM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay that explains it...I needed to put in some error checking because if the target investment is less than the initial investment then of course it's going to return a zero.
So it works now...it returns the right value if you put a proper initial investment and ending investment amount, and otherwise it gives you an error message stating that your initial investment needs to be less than your target investment (unless of course they want it to be a debt calculator instead).
Thanks so much. I think now that I'm looking at the finished program I'm seeing how this comes together more.

 
Old April 29th, 2008, 07:05 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem, glad you get it working!

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
[HELP] Problems in Asp.net vb, database nielniel ASP.NET 3.5 Basics 2 July 7th, 2008 05:39 PM
Asp.net Logout problems hemal_301080 ASP.NET 1.0 and 1.1 Professional 1 August 6th, 2006 12:16 PM
Problems with debugging ASp.net ocabrera70 ASP.NET 2.0 Basics 1 March 1st, 2006 03:49 PM
New to ASP.NET w/ C# and having problems digitaltoddy BOOK: Beginning ASP.NET 1.0 1 September 20th, 2004 07:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.