My program allows the user to input values of hours and minutes into an array of predefined length. I want to have this button called add for a form I'm creating to allow multiple inputs from the user until the array is fully inhabited. Then when it's done, to call a sortArray() method They way it is now it only allows one input then it throws an exception. How do I go about this?
private void addButton_Click(object sender, EventArgs e)
{
int index = 0;
try
{
while (index <= array.Length)
{
minutes = Int32.Parse(minutesTextBox.Text);
hours = Int32.Parse(hoursTextBox.Text);
MessageBox.Show("You have successfully entered a time!");
array[index] = new RandomClass.Time(hours, minutes);
index = index + 1;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.GetType().FullName);
MessageBox.Show("Please only input integer numbers. Start again from the beginning");
hoursTextBox.Text = null;
minutesTextBox.Text = null;
array = null;
arrayLength = null;
}
MessageBox.Show("Please choose what order you want arrange the sort!");
FileA.RandomClass.sortArray(array);
}