1

I set up my breakpoint at this statement,

futureValue= (futureValue + monthlyInvestment) * (1+ monthlyInterestRate);

but if I want to create conditions to determine each month (this starts a 0) and the future value of each month or index, how could I do this in the conditional expression dialog box using a breakpoint? I did research for a similar question on this website and only found these pages: (Set breakpoints in an ASP.NET Web Site Project, Break points aspx pages, How to set conditional breakpoints in Visual Studio?). Also, after I set up the breakpoint, wouldn't it display those specific month and futureValue values in web application program if I run. Here is my C# code only since I think it's the only file that I think needs to be here.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace XEx05FutureValue
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                for (int i = 50; i <= 500; i += 50)
                    ddlMonthlyInvestment.Items.Add(i.ToString());
        }

        protected void btnCalculate_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                int monthlyInvestment = Convert.ToInt32(ddlMonthlyInvestment.SelectedValue);
                decimal yearlyInterestRate = Convert.ToDecimal(txtInterestRate.Text);
                int years = Convert.ToInt32(txtYears.Text);

                decimal futureValue = this.CalculateFutureValue(monthlyInvestment,
                    yearlyInterestRate, years);

                lblFutureValue.Text = futureValue.ToString("c");
            }
        }

        protected decimal CalculateFutureValue(int monthlyInvestment,
        decimal yearlyInterestRate, int years)
        {
            int months = years * 12;
            decimal monthlyInterestRate = yearlyInterestRate / 12 / 100;
            decimal futureValue = 0;
            for (int i = 0; i < months; i++)
            {
                futureValue = (futureValue + monthlyInvestment)
                    * (1 + monthlyInterestRate);
            }
            return futureValue;
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            ddlMonthlyInvestment.SelectedIndex = 0;
            txtInterestRate.Text = "";
            txtYears.Text = "";
            lblFutureValue.Text = "";
        }
    }
}
Sach
  • 10,091
  • 8
  • 47
  • 84
dorakta
  • 75
  • 8
  • I don't understand why you would like a breakpoint like this. And why would you like that visual studio stop on those values? – Bestter Sep 20 '17 at 20:39
  • @Bestter Do you think you can help me understand this better? In your opinion, what would be a better way of doing this? So I can see the month and futurevalue values. – dorakta Sep 20 '17 at 20:43
  • @Bestter It's called debugging. I just want to see if it will print out the future value after 1 month, 5 months, 10 months in the actual web application. Is this possible? – dorakta Sep 20 '17 at 20:46
  • @dorakta and, if instead breakpoints, print those results in your page and/or store such values in a `List<>`? – Mauricio Arias Olave Sep 20 '17 at 21:06
  • @Mauricio Arias Olave So how will breakpoints come into play at? So I literally have to code them into the web application. I guess that would make more sense. – dorakta Sep 20 '17 at 21:10
  • @dorakta `how could I do this in the conditional expression dialog box using a breakpoint?` Also, if you set a breakpoint and using F10 key you can check the "Locals" tab - as is shown in this [image](https://i.stack.imgur.com/UABhA.png)? – Mauricio Arias Olave Sep 20 '17 at 21:17
  • @Mauricio Arias Olave How can set up a breakpoint at the best point for determining the month number and future value each time through the loop? – dorakta Sep 20 '17 at 21:33
  • @MauricioAriasOlave-Never mind the breakpoint would come after the calculation has made done. So the breakpoint would be the closing brace of the for statement. – dorakta Sep 21 '17 at 13:06

0 Answers0