Micheal Zwane

Micheal Zwane

  • NA
  • 3
  • 946

I would like to add code for error detection in this code,

Feb 8 2015 8:16 PM
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 Programming
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
int days = 1;
while (days <= 31)
{
comboBoxday.Items.Add(days);
days = days + 1;
}
int month = 1;
while (month <= 12)
{
comboBoxmonth.Items.Add(month);
month = month + 1;
}
int year = 1900;
while (year <= 2015)
{
comboBoxyear.Items.Add(year);
year = year + 1;
}
}

private void timer1_Tick(object sender, EventArgs e)
{

textBoxDate.Text = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString();

}
//String Birthday puts together the comboboxes to produce combined output
private void buttonAge_Click(object sender, EventArgs e)
{
string Todaystring = DateTime.Now.ToLongDateString();
DateTime Todaydate = DateTime.Parse(Todaystring);

string Birthday;
Birthday = comboBoxday.SelectedItem.ToString() + " " + comboBoxmonth.SelectedItem.ToString() + " " + comboBoxyear.SelectedItem.ToString();
DateTime Birthdaydate = DateTime.Parse(Birthday);

TimeSpan dateDiff;
dateDiff = Todaydate.Subtract(Birthdaydate);

MessageBox.Show(textBoxName.Text + " your age in days is: " + dateDiff.Days);
}
}

Answers (2)