adding number of times a button is clicked in order to multiply that by a set number---How???? (code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I need some help on how to add the number of times btnAddItems is clicked in order to know how many times to multiply that by the 750 tuitionFee value. The button may be clicked once, twice, three times etc...Once this value is totaled I need to add this
amount to totalDue for an overall balance due. I have no idea where to insert the code or what the code needs to be. I have tried numerous times with the end result being frustration. I am lost, can someone please show me what I need to do. I have worked on
this for hours trying to figure it out.
Once a course title is selected, course id, titile, and credit hours are added in 3 different arrays. There is a calculate button to calculate tuition, fees, and total balance and have all the data displayed.
using System.Windows.Forms;<br/>
using System.Xml;<br/>
using System.IO;<br/>
<br/>
namespace arrayarray<br/>
{<br/>
public partial class FrmCourses : Form<br/>
{<br/>
static int MAX_SIZE = 10;<br/>
string[] CourseCallNumber = new string [MAX_SIZE];<br/>
string[] CourseID = new string[MAX_SIZE];<br/>
string[] CourseTitle = new string[MAX_SIZE];<br/>
int[] CreditHours = new int[MAX_SIZE];<br/>
string[] CourseInstructor = new string[MAX_SIZE];<br/>
string[] CourseLocation = new string[MAX_SIZE];<br/>
<br/>
<br/>
int courseCount = 0; // array counter variable set to zero<br/>
int itemSelect = 0; // counter for listbox display<br/>
int tuitionFee = 750;// hardcode the value since all were the same credit hour value. Just need to multiply by number of

times the btnAddItems is clicked<br/>
//int ttlTuition; //how would you calculate the number of times btnAddItem has been clicked or what is the best way<br/>
//int totalDue;// totalDue = ttlTuition + 450 <br/>
<br/>
<br/>
public FrmCourses()<br/>
{<br/>
InitializeComponent();<br/>
}<br/>
<br/>
<br/>
private void FrmCourses_Load(object sender, EventArgs e)<br/>
{<br/>
lstDisplay.Items.Add(" Course and Cost Information");<br/>
lstDisplay.Items.Add("__________________________________________________________________________");<br/>
lstDisplay.Items.Add("");<br/>
<br/>
<br/>
<br/>
XmlTextReader r = new XmlTextReader(@".Courses.xml");<br/>
r.WhitespaceHandling = WhitespaceHandling.None;<br/>
<br/>
<br/>
while (r.Name != "Course")<br/>
r.Read();<br/>
while (r.Name == "Course")<br/>
{<br/>
r.ReadStartElement("Course");<br/>
r.ReadElementString("CallNumber"); //read only<br/>
CourseID[courseCount] = r.ReadElementString("CourseID");<br/>
CourseTitle[courseCount] = r.ReadElementString("CourseTitle");<br/>
CreditHours[courseCount] = Convert.ToInt32(r.ReadElementString("CreditHours"));<br/>
r.ReadElementString("Instructor"); //read only<br/>
r.ReadElementString("Location"); //read only<br/>
r.ReadEndElement();<br/>
courseCount++;<br/>
}<br/>
r.Close();<br/>
for (int i = 0; i < courseCount; i++)<br/>
cboItems.Items.Add(CourseID);<br/>
}<br/>
<br/>
<br/>
<br/>
private void cboItems_SelectedIndexChanged(object sender, EventArgs e)<br/>
{<br/>
txtCourseID.Text = CourseID[cboItems.SelectedIndex];// show course ID in text box<br/>
txtCourseTitle.Text = CourseTitle[cboItems.SelectedIndex];// show course title in text box<br/>
txtCreditHours.Text = CreditHours[cboItems.SelectedIndex].ToString();// show credit hours in text box<br/>
}<br/>
<br/>
private void btnAddItem_Click(object sender, EventArgs e)// add new courses when clicked <br/>
<br/>
{<br/>
itemSelect = cboItems.SelectedIndex;<br/>
string lineFormat = "{0,-2}{1,-13}{2,-35}{3,-10}{4,-15:C}";// output data display for new items selected<br/>
lstDisplay.Items.Add(string.Format(lineFormat, "", CourseID[itemSelect], CourseTitle[itemSelect], CreditHours[itemSelect], tuitionFee));<br/>
}<br/>
<br/>
private void btnClose_Click(object sender, EventArgs e) <br/>
{<br/>
this.Close();<br/>
}<br/>
<br/>
<br/>
// Calculate Tuition and final display lines<br/>
private void btnCalculate_Click(object sender, EventArgs e)<br/>
{<br/>
/////ttlTuition = lstDisplay.Items.Count * tuitionFee; I tried this not having an idea<br/>
/////int totalDue = ttlTuition + 450; these two do nothing<br/>
<br/>
<br/>
lstDisplay.Items.Add( "-----------------------------------------------------------------------");<br/>
lstDisplay.Items.Add(string.Format(" TOTAL TUITION FEES:",ttlTuition)); <br/>
lstDisplay.Items.Add(string.Format(" SEMESTER FEE: $450.00"));<br/>
lstDisplay.Items.Add(string.Format(" BALANCE DUE:",totalDue)); // Total Amount Due <br/>
}<br/>
<br/>
<br/>
private void lstDisplay_SelectedIndexChanged(object sender, EventArgs e)<br/>
{<br/>
<br/>
<br/>
}<br/>
<br/>
}<br/>
<br/>
}


View the full article
 
Back
Top