in my program, i have a button that shows me everyone's (a list of people's) birthdays in the next 14 days. it works as follows:
main form:
private void buttonBirthdaysNext2Weeks_Click(object sender, EventArgs e)
{
int days = (int)numericUpDown1.Value;
string caption = string.Format("Birthdays in next {0} days", days);
string message = birthdays.UpComingBirthdays(days);
if (message == "")
{
message = "No birthdays found!";
}
MessageBox.Show(message, caption, MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
class with the method that is called:
public string UpComingBirthdays(int days)
{
string names = "";
foreach (Person person in people)
{
if (person.HowManyDaysTillBirthday() <= 14)
{
int number = person.HowManyDaysTillBirthday();
//Debug.Print(number.ToString());
// Debug.print(int days2 = HowManDaysTillBirthday(););
if (names != "")
{
names = names + Environment.NewLine; // Each person name and details will be printed on new line
}
names = names + person.FirstName + " " + person.LastName + " " + person.DateOfBirth(); //all these details (first, last and dob) will be printed/given to names string
}
}
return names;
}
i am attempting something similar. i want to show how birthdays for each given month; rather than a button click event, this would be done using a combobox. the combobox lists each month; the user selects the month; a messagebox then shows each person/birthday in that month. very similar to the previous code, then. yet, i am having trouble and encountering the following error: FormatException was unhandled.
after creating a combobox, and inputting each month manually as an item in its Items (collection) property, here's what i've tried:
public void comboBoxMonthsInTheYear_SelectedIndexChanged(object sender, EventArgs e)
{
int monthWanted = int.Parse(comboBoxMonthsInTheYear.SelectedItem.ToString());
string caption = string.Format("Birthdays in monthWanted", monthWanted);
string message = birthdays.birthdaysInMonth(monthWanted);
}
&
public string birthdaysInMonth(int monthWanted)
{
string names = "";
foreach (Person person in people)
{
if (person.MonthBorn == monthWanted)
{
if (names != "")
{
names = names + Environment.NewLine; // Each person name and details will be printed on new line
}
names = names + person.FirstName + " " + person.LastName + " " + person.DateOfBirth(); //all these details (first, last and dob) will be printed/given to names string
}
}
return names;
}
}
upon clicking a month in the combobox, the FormatException error is presented. i'm unsure where to proceed from here. any advice is appreciated; if not, thank you for reading! i apologize in advance if you feel my question is neither well-written nor worthy of being posted here (it's very basic stuff, admittedly).