Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

Add total calculations to form

The form pictured here http://screencast.com/t/ETJEKR16dpKE works perfectly with the exception of the total box.  Can someone tell me how to enter the code for the total box?
/*Purpose: To calculate revenue from stadium ticket sales.*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _304_PennerT_Lab03
{
    public partial class stadiumSeatingForm : Form
    {
        public stadiumSeatingForm()
        {
            InitializeComponent();
        }
        private void calculateRevenueButton_Click_1(object sender, EventArgs e)
        {
            // Declare Named Constants
               
                const decimal CLASS_A_SEATS = 15.00m; const decimal CLASS_B_SEATS = 12.00m; const decimal CLASS_C_SEATS = 9.00m;
            
            // Declare Varialbles
               
                decimal classATickets; decimal classBTickets; decimal classCTickets;
                decimal classARevenue; decimal classBRevenue; decimal classCRevenue;
            
            // Convert Text Box Values (which are string values) to the appropriate data type using a Parse method and assign to related variable.
               
                classATickets = decimal.Parse(classATicketsSalesBox.Text); classBTickets = decimal.Parse(classBTicketsSalesBox.Text); classCTickets = decimal.Parse(classCTicketsSalesBox.Text);
            
            // Process Calculations
               
                classARevenue = classATickets * CLASS_A_SEATS; classBRevenue = classBTickets * CLASS_B_SEATS; classCRevenue = classCTickets * CLASS_C_SEATS;
            
            // Display Numeric Output to appropriate control by converting the numeric value to a string using the ToString method.
               
                classARevenueBox.Text = classARevenue.ToString("c"); classBRevenueBox.Text = classBRevenue.ToString("c"); classCRevenueBox.Text = classCRevenue.ToString("c");
        }
        private void clearButton_Click(object sender, EventArgs e)
        {
            // Clear form and set focus
               
                classATicketsSalesBox.Text = " "; classBTicketsSalesBox.Text = " "; classCTicketsSalesBox.Text = " ";
                classARevenueBox.Text = " "; classBRevenueBox.Text = " "; classCRevenueBox.Text = " ";
                totalRevenueBox.Text = " ";
        }
        private void exitButton_Click(object sender, EventArgs e)
        {
            // Close application
                
                this.Close();
        }
    }
}

Open in new window

0
rtod2
Asked:
rtod2
  • 8
  • 7
9 Solutions
 
QPRCommented:
Does this work?
theTotal = decimal.Parse(classATicketsSalesBox.Text) + decimal.Parse(classBTicketsSalesBox.Text) + decimal.Parse(classCTicketsSalesBox.Text);
totalRevenueBox.Text = theTotal;

Open in new window

0
 
rtod2Author Commented:
I tried putting it in the places shown in red here.  What am I doing wrong?  http://screencast.com/t/EMY8bqFlaHG
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
The variable TotalRevenue is not declared or not accessible at that point in the code.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
QPRCommented:
where abouts is totalRevenue declared?
Try declaring it within calculateRevenueButton_Click_1 under your declare variables comment
0
 
rtod2Author Commented:
hmm.

Here is the source code.  What do I put where?

/* 304_PennerT_Lab03
Ted R Penner
000305507
Self-Paced, Per prior discussion with instuctor.
Oct 12, 2011
Purpose: To calculate revenue from stadium ticket sales.*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _304_PennerT_Lab03
{
    public partial class stadiumSeatingForm : Form
    {
        public stadiumSeatingForm()
        {
            InitializeComponent();
        }
        private void calculateRevenueButton_Click_1(object sender, EventArgs e)
        {
            // Declare Named Constants
               
                const decimal CLASS_A_SEATS = 15.00m; const decimal CLASS_B_SEATS = 12.00m; const decimal CLASS_C_SEATS = 9.00m;
                
            // Declare Varialbles
               
                decimal classATickets; decimal classBTickets; decimal classCTickets;
                decimal classARevenue; decimal classBRevenue; decimal classCRevenue;

            // Convert Text Box Values (which are string values) to the appropriate data type using a Parse method and assign to related variable.
               
                classATickets = decimal.Parse(classATicketsSalesBox.Text); classBTickets = decimal.Parse(classBTicketsSalesBox.Text); classCTickets = decimal.Parse(classCTicketsSalesBox.Text);
            
            // Process Calculations
               
                classARevenue = classATickets * CLASS_A_SEATS; classBRevenue = classBTickets * CLASS_B_SEATS; classCRevenue = classCTickets * CLASS_C_SEATS;

            // Display Numeric Output to appropriate control by converting the numeric value to a string using the ToString method.
               
                classARevenueBox.Text = classARevenue.ToString("c"); classBRevenueBox.Text = classBRevenue.ToString("c"); classCRevenueBox.Text = classCRevenue.ToString("c");
                totalRevenueBox.Text = totalRevenue;
        }
        private void clearButton_Click(object sender, EventArgs e)
        {
            // Clear form and set focus
               
                classATicketsSalesBox.Text = " "; classBTicketsSalesBox.Text = " "; classCTicketsSalesBox.Text = " ";
                classARevenueBox.Text = " "; classBRevenueBox.Text = " "; classCRevenueBox.Text = " ";
                totalRevenueBox.Text = " ";
        }
        private void exitButton_Click(object sender, EventArgs e)
        {
            // Close application
                
                this.Close();
        }
    }
}

Open in new window

0
 
QPRCommented:
           // Declare Varialbles
               
                decimal classATickets; decimal classBTickets; decimal classCTickets;
                decimal classARevenue; decimal classBRevenue; decimal classCRevenue;
                decimal totalRevenue;
0
 
rtod2Author Commented:
Excellent, thank you!  Here is all the new source code but I am getting the wrong total in the total row which should produce the results of the calculations totaled
/*Purpose: To calculate revenue from stadium ticket sales.*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _304_PennerT_Lab03
{
    public partial class stadiumSeatingForm : Form
    {
        public stadiumSeatingForm()
        {
            InitializeComponent();
        }
        private void calculateRevenueButton_Click_1(object sender, EventArgs e)
        {
            // Declare Named Constants
               
                const decimal CLASS_A_SEATS = 15.00m; const decimal CLASS_B_SEATS = 12.00m; const decimal CLASS_C_SEATS = 9.00m;
                
            // Declare Varialbles
               
                decimal classATickets; decimal classBTickets; decimal classCTickets;
                decimal classARevenue; decimal classBRevenue; decimal classCRevenue;
                decimal totalRevenue;
            
            // Convert Text Box Values (which are string values) to the appropriate data type using a Parse method and assign to related variable.
               
                classATickets = decimal.Parse(classATicketsSalesBox.Text); classBTickets = decimal.Parse(classBTicketsSalesBox.Text); classCTickets = decimal.Parse(classCTicketsSalesBox.Text);
                totalRevenue = decimal.Parse(classATicketsSalesBox.Text) + decimal.Parse(classBTicketsSalesBox.Text) + decimal.Parse(classCTicketsSalesBox.Text);
           
            // Process Calculations
               
                classARevenue = classATickets * CLASS_A_SEATS; classBRevenue = classBTickets * CLASS_B_SEATS; classCRevenue = classCTickets * CLASS_C_SEATS;

            // Display Numeric Output to appropriate control by converting the numeric value to a string using the ToString method.
               
                classARevenueBox.Text = classARevenue.ToString("c"); classBRevenueBox.Text = classBRevenue.ToString("c"); classCRevenueBox.Text = classCRevenue.ToString("c");
                totalRevenueBox.Text = totalRevenue.ToString("C");
        }
        private void clearButton_Click(object sender, EventArgs e)
        {
            // Clear form and set focus
               
                classATicketsSalesBox.Text = " "; classBTicketsSalesBox.Text = " "; classCTicketsSalesBox.Text = " ";
                classARevenueBox.Text = " "; classBRevenueBox.Text = " "; classCRevenueBox.Text = " ";
                totalRevenueBox.Text = " ";
        }
        private void exitButton_Click(object sender, EventArgs e)
        {
            // Close application
                
                this.Close();
        }
    }
}

Open in new window

0
 
rtod2Author Commented:
Screenshot of what is showing in the total row >> http://screencast.com/t/vcynn4GVkbgS
0
 
QPRCommented:
Strange. Are you able to set the text box value to totalRevenue without using tostring

totalRevenueBox.Text = totalRevenue
0
 
QPRCommented:
ignore that, you do need tostring()
I've just done a test (below) and it works fine.
Ahhh your totalrevenue is counting your class textboxes and not your revenue testboxes
private void button1_Click(object sender, EventArgs e)
        {
            decimal txt1 = decimal.Parse(textBox1.Text);
            decimal txt2 = decimal.Parse(textBox2.Text);
            decimal txt3 = decimal.Parse(textBox3.Text);

            decimal theTotal = txt1 + txt2 + txt3;

            textBox4.Text = theTotal.ToString();

        }

Open in new window

0
 
rtod2Author Commented:
Nope.  

If I do totalRevenueBox.Text = totalRevenue; then it gives me Cannot implicitly convert type 'decimal' to 'string'

What I am seeing is that it is adding the wrong column of numbers.  It should be adding the results in the revenue column.  
0
 
QPRCommented:
Yes, you want to set it to to the total of
decimal classARevenue; decimal classBRevenue; decimal classCRevenue;
not
decimal classATickets; decimal classBTickets; decimal classCTickets;

same code as before, just change the values in the + bit I posted
theTotal = decimal.Parse(classARevenue.Text) + decimal.Parse(classBclassARevenue.Text) + decimal.Parse(classCclassARevenue.Text);
totalRevenueBox.Text = theTotal;

Open in new window

0
 
rtod2Author Commented:
ok, error here >> http://screencast.com/t/CbhNh9rsfLFz is thrown when running it.  I got part way I think though as there are no syntactical errors until running it.

http://screencast.com/t/CbhNh9rsfLFz

Open in new window

 Please advise further.
0
 
QPRCommented:
put your textbox values into your variables first
then add your three variables up and put then put them into the total variable

classarevenue = decimal.parse(classarevenuebox.text);
etc

then
totalRevenue = classarevenue + classbrevenue + classcrevenue
0
 
rtod2Author Commented:
QPR, Thank you but you lost me.  What would I change here
/* 304_PennerT_Lab03
Ted R Penner
000305507
Self-Paced, Per prior discussion with instuctor.
Oct 12, 2011
Purpose: To calculate revenue from stadium ticket sales.*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _304_PennerT_Lab03
{
    public partial class stadiumSeatingForm : Form
    {
        public stadiumSeatingForm()
        {
            InitializeComponent();
        }
        private void calculateRevenueButton_Click_1(object sender, EventArgs e)
        {
            // Declare Named Constants
               
                const decimal CLASS_A_SEATS = 15.00m; const decimal CLASS_B_SEATS = 12.00m; const decimal CLASS_C_SEATS = 9.00m;
                
            // Declare Varialbles
               
                decimal classATickets; decimal classBTickets; decimal classCTickets;
                decimal classARevenue; decimal classBRevenue; decimal classCRevenue;
                decimal totalRevenue;
            
            // Convert Text Box Values (which are string values) to the appropriate data type using a Parse method and assign to related variable.
               
                classATickets = decimal.Parse(classATicketsSalesBox.Text); classBTickets = decimal.Parse(classBTicketsSalesBox.Text); classCTickets = decimal.Parse(classCTicketsSalesBox.Text);
                totalRevenue = decimal.Parse(classARevenueBox.Text);

            // Process Calculations
               
                classARevenue = classATickets * CLASS_A_SEATS; classBRevenue = classBTickets * CLASS_B_SEATS; classCRevenue = classCTickets * CLASS_C_SEATS;
                totalRevenue = classARevenue + classBRevenue + classCRevenue;
           
            // Display Numeric Output to appropriate control by converting the numeric value to a string using the ToString method.
               
                classARevenueBox.Text = classARevenue.ToString("c"); classBRevenueBox.Text = classBRevenue.ToString("c"); classCRevenueBox.Text = classCRevenue.ToString("c");
                totalRevenueBox.Text = totalRevenue.ToString();
        }
        private void clearButton_Click(object sender, EventArgs e)
        {
            // Clear form and set focus
               
                classATicketsSalesBox.Text = " "; classBTicketsSalesBox.Text = " "; classCTicketsSalesBox.Text = " ";
                classARevenueBox.Text = " "; classBRevenueBox.Text = " "; classCRevenueBox.Text = " ";
                totalRevenueBox.Text = " ";
        }
        private void exitButton_Click(object sender, EventArgs e)
        {
            // Close application
                
                this.Close();
        }
    }
}

Open in new window

to prevent the error shown here http://screencast.com/t/CbhNh9rsfLFz
0
 
QPRCommented:

theTotal = decimal.Parse(classARevenueBox.Text) + decimal.Parse(classBRevenueBox.Text) + decimal.Parse(classCRevenueBox.Text);
totalRevenueBox.Text = theTotal;

Open in new window

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now