Hello Daniweb, I am building a simple form to calculate and display a discounted price using VB. Here is what I am trying to do... lblDiscount = txtPercent / 100 * txtPrice
lblPrice = txtPrice - lblDiscount
Here is the code that I have so far...I am just a little stuck and a little hint in the right direction would be awsome.

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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            decimal percent = Convert.ToDecimal(txtPercent.Text);
            decimal price = Convert.ToDecimal(txtPrice.Text);
            lblDiscount.Text = lblDiscount.ToString("c");
            decimal tltprice = Convert.ToDecimal(lblPrice.Text);

            decimal lbldiscount = percent / 100 * price;


        }
    }
}

Ok so I have been playing around with this for a bit now and here is what my new code looks like..I now get CS0161: '_Default.CalculateDiscount(decimal, decimal)': not all code paths return a value

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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            decimal percent = Convert.ToDecimal(txtPercent.Text);
            decimal price = Convert.ToDecimal(txtPrice.Text);

            decimal discount = this.CalculateDiscount(percent, price);

            lblDiscount.Text = discount.ToString("c");
        }
    }              


        protected decimal CalculateDiscount(decimal percent, decimal price)
        {
            decimal discount = percent / 100 * price;
        }

}

Well I figured it out. Sometimes I just try to do to much and complicate things when all you need to do is simplify it. Here is what I did...

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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            decimal percent = Convert.ToDecimal(txtPercent.Text);
            decimal price = Convert.ToDecimal(txtPrice.Text);

            decimal discount = percent / 100 * price;
            decimal tltPrice = price - discount;

            lblDiscount.Text = discount.ToString("c");
            lblPrice.Text = tltPrice.ToString("c");
        }

    }        

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.