Hi,
I'm brand new to C# and more proficient in VBA but I was designing something basic for work purposes and I'm stuck. The form works well when data is entered, however I'm getting an error when my windows form app is blank and i think the cause is the conversion of the timespan difference to decimal? I used tryparse,parse,convert and it is still not working properly when the form is blank and the button is clicked. Any suggestions would be greatly appreciated! Error message below and code below that.
Thanks!
I'm brand new to C# and more proficient in VBA but I was designing something basic for work purposes and I'm stuck. The form works well when data is entered, however I'm getting an error when my windows form app is blank and i think the cause is the conversion of the timespan difference to decimal? I used tryparse,parse,convert and it is still not working properly when the form is blank and the button is clicked. Any suggestions would be greatly appreciated! Error message below and code below that.
Thanks!
C#:
private void Button1_Click(object sender, EventArgs e)
{
if
(textBox4.Text == "")
{
MessageBox.Show("Please Enter Payment Agreement Amount");
}
if
(comboBox2.Items.Count == 0)
{
MessageBox.Show("Please Select A Payment Type");
}
else
{
DateTime date1 = dateTimePicker3.Value;
DateTime date2 = dateTimePicker2.Value;
TimeSpan difference = date1 - date2;
decimal TotalWeeks = difference.Days / 7;
decimal PayTotal = decimal.Parse(textBox4.Text);
decimal PaymentWeeks = TotalWeeks * PayTotal;
decimal TotalMonths = difference.Days / 30;
decimal PaymentMonths = TotalMonths * PayTotal;
if (comboBox2.SelectedItem == "Months")
textBox3.Text = String.Format("$" + "{0:0,0.00}", Convert.ToDecimal(PaymentMonths));
if (comboBox2.SelectedItem == "Weeks")
textBox3.Text = String.Format("$" + "{0:0,0.00}", Convert.ToDecimal(PaymentWeeks));
}
Attachments
Last edited by a moderator: