I need help with breaking my algorithm into modules. The reason why is because the following code at the moment is essentially duplicated three times for each calculate button on my GUI Windows Forms Application. I was wondering if I break it down in to sub-routines this can be done? Can anyone help me with this? public void park1() { string allotedTime = txtTimeLimit1.Text; string startTime = txtEntryTime1.Text; string endTime = txtExitTime1.Text; if (String.IsNullOrEmpty(allotedTime) || String.IsNullOrEmpty(startTime) || String.IsNullOrEmpty(endTime)) { MessageBox.Show("Enter all time values"); } else { TimeSpan alloted = TimeSpan.Parse(allotedTime); DateTime start = DateTime.Parse(startTime); DateTime end = DateTime.Parse(endTime); if (start > end) end = end.AddDays(1); TimeSpan duration = end.Subtract(start); //If the start time is greater than end that means the diff is above 12 hours //So subtracting the hours from a day to get the number of hours used if (TimeSpan.Compare(alloted, duration) == -1) if (TimeSpan.Compare(alloted, duration) == -1) { overTime1++; } completeTime1++; lblOverTime1.Text = "" + overTime1; int percentage = (overTime1 * 100) / completeTime1; lblOverTimePercentage1.Text = "" + percentage; if (percentage > 50) { warnWarden(); } } }
G
George Bradley
@George Bradley