Hi, I am having an issue with my code and need a bit of help. I need the beginni
ID: 3665719 • Letter: H
Question
Hi, I am having an issue with my code and need a bit of help. I need the beginning balance label to change to available balance and have the withdrawal and/or deposit amount add up with beginning balance to become the available balance. Thank you!!
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
beginBalance = 0.0;
availBalance = 0.0;
textBox1.Visible = false;
textBox2.Visible = false;
textBox3.Visible = false;
btnContinue.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
btnSubmit.Visible = false;
btnReset.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Text = "0";
textBox3.Text = "0";
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
int flag = 0;
beginBalance = Convert.ToDouble(textBox3.Text);
while (flag == 0)
{
if (beginBalance < 0)
textBox3.Text = "";
else
{
flag = 1;
availBalance = beginBalance;
}
}
btnContinue.Visible |= flag == 1;
int parsedValue;
if (!int.TryParse(textBox3.Text, out parsedValue))
{
MessageBox.Show("Must be a numeric entry");
return;
}
}
private void button3_Click(object sender, EventArgs e)
{
textBox4.Visible = true;
textBox5.Visible = true;
btnReset.Visible = true;
textBox1.Enabled = false;
textBox2.Enabled = false;
textBox3.Enabled = false;
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
int flag = 0;
while (flag == 0)
{
withdrawAmount = Convert.ToDouble(textBox4.Text);
if (withdrawAmount < 0 || withdrawAmount < availBalance)
textBox4.Text = "";
else
flag = 1;
}
if (flag == 1)
btnSubmit.Visible = true;
int parsedValue;
if (!int.TryParse(textBox4.Text, out parsedValue))
{
MessageBox.Show("Must be a numeric entry");
return;
}
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
int flag = 0;
while (flag == 0)
{
depositAmount = Convert.ToDouble(textBox4.Text);
if (depositAmount < 0)
textBox5.Text = "";
else
flag = 1;
}
if (flag == 1)
btnSubmit.Visible = true;
}
private void button4_Click(object sender, EventArgs e)
{
if (withdrawAmount > 0)
availBalance = availBalance - withdrawAmount;
else if (depositAmount > 0)
availBalance = availBalance + depositAmount;
textBox3.Text = Convert.ToString(availBalance);
}
private void button5_Click(object sender, EventArgs e)
{
// code for Reset button
textBox4.Text = "0";
textBox5.Text = "0";
textBox2.Text = "0";
textBox3.Text = "0";
textBox1.Enabled = true;
textBox2.Enabled = true;
textBox3.Enabled = true;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
int parsedValue;
if (!int.TryParse(textBox2.Text, out parsedValue))
{
MessageBox.Show("Must be a numeric entry");
return;
}
}
}
}
Explanation / Answer
Try As per the below code
Ideally the setText() method and others that alter the component have to be called from the EDT itself to avoid bugs... This is not the case in the example I gave you. If you want to do it use this method:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.