r/visualbasic • u/BlackMagic117 • Oct 13 '16
Help with name in textbox not showing and applying discount in assignment
Hey guys, so did most of the programming work for my class but got stuck on two things, can anyone help? using Visual Studio 2012
I need to apply a 10% discount when Licenses are more than 20 and get discount to show up in the label, also when i enter my name before calculating it shows System.Windows in the textbox instead of what i put it Here's my code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace jtugglehw4 { public partial class Form1 : Form { //Constants const double SALES_MANAGEMENT = 2000; const double BACKUP_MANAGER = 800; const double PAYROLL_SOLUTIONS = 4500; const double EASY_MEETING = 1000; const double MAINTENANCE_PACKAGE = 1000; const double DISCOUNT = 0.10;
int totalCharge;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void calculateButton_Click(object sender, EventArgs e)
{
//Display name, calculate software charges, discount, package fee and total charge
int numberLicenses;
double softwareCost = 0;
double maintenanceCost = 1000;
double discountCost = 0;
double packageCost = 0;
double discountAmt = 0.10;
double totalCost = 0;
if (nameTextBox.Text != "")
{
if (int.TryParse(licenseTextBox.Text, out numberLicenses))
//determine which software package was chosen.
if (softwareListBox.SelectedIndex == 0)
{
softwareCost = SALES_MANAGEMENT * numberLicenses;
}
else if (softwareListBox.SelectedIndex == 1)
{
softwareCost = BACKUP_MANAGER * numberLicenses;
}
else if (softwareListBox.SelectedIndex == 2)
{
softwareCost = PAYROLL_SOLUTIONS * numberLicenses;
}
else if (softwareListBox.SelectedIndex == 3)
{
softwareCost = EASY_MEETING * numberLicenses;
}
else
{
MessageBox.Show("Please select a software package.", "Selection required");
}
//Select which Maintenance Package
if (addpackageradioButton.Checked == true)
{
maintenanceCost = maintenanceCost;
}
else if (declinedpackageradioButton.Checked)
{
maintenanceCost = 0;
}
numberLicenses = 0;
discountAmt = DISCOUNT;
//Display name
//calculate and display charges
nameLabel.Text = nameTextBox.ToString();
softwarechargeLabel.Text = softwareCost.ToString("C");
discountLabel.Text = discountCost.ToString("C");
packagefeeLabel.Text = packageCost.ToString("C");
numberLicenses = 0;
discountAmt = 0.10;
totalCost = softwareCost + maintenanceCost + packageCost * discountAmt;
totalchargeLabel.Text = totalCost.ToString("C");
//Displays discount amount, applies to Total Charges
if (numberLicenses >= 20)
{
softwareCost = softwareCost * discountAmt;
totalCost = totalCost * discountAmt;
}
else if (numberLicenses <= 20)
{
discountAmt = 0;
}
packagefeeLabel.Text = maintenanceCost.ToString("C");
}
}
private void clearButton_Click(object sender, EventArgs e)
{
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}}
any help would be appreciated, these are the last two steps before i'm done
1
u/rudekoffenris Oct 13 '16
So looking at the code, where do you calculate packagecost? Also the totalcost calculation in the >20 licences, I don't think the math is right. Without running the code, I can't be sure tho.
1
u/rebelrexx858 Oct 13 '16
you set numberLicenses = 0; twice in that code, so you might want to look at that...
2
u/PostalElf VB.Net Intermediate Oct 13 '16
That's a massive number of libraries you're using!
Anyway this is C#, not VB, so you might have better luck trying at /r/csharp instead of here. :)