// function to generat the exercise information the first time. // pass in the exercise class to be printed private void generateContents(PlayerData.Exercise workout) { // preparing information for processing text5_array = workout.get_dates_info().Split('\n'); // parcing data returned from Exercise class into lines date_array = date_field.text.Split('/'); // parcing date field into month, day, and year System.Int32.TryParse(date_array[0], out date_month); // converting month to int System.Int32.TryParse(date_array[1], out date_day); // converting day to int System.Int32.TryParse(date_array[2], out date_year); // converting year to int text_field5.text = ""; // clearing current contents in field // looping through al the lines returned from the Exercise class // max number of lines printed will be 6 for (int i = current_pos; i < text5_array.Length && i < (6 + current_pos); i++) { // checking to see if we are placed in the correct position for the selected date if (!date_found) { info_date_array = text5_array[i].Split('\t'); //parcing line to get date info info_date_array = info_date_array[0].Split('/'); //parcing date into month, day, and year // a redunant check to prevent multiple fail to parse function if (System.Int32.TryParse(info_date_array[0], out info_month)) //TryParse returns bool if function executed { System.Int32.TryParse(info_date_array[2], out info_year); //TryParse will save string into int variable after out // checking to see if the selected date is before or after the current position in the stored data if (date_year > info_year) // if selected date is larger go to next entry { current_pos++; } else if (date_year == info_year) // if selected date is equal, we need to check month { if (date_month > info_month) // if selected month is larger, go to next entry { current_pos++; } else if (date_month == info_month) // if selected month is equal, we need to check days { System.Int32.TryParse(info_date_array[1], out info_day); // parse day into int if (date_day > info_day) // if selected day is larger, go to next entry { current_pos++; } else // if selected day is equal or larger, we found where to start { date_found = true; i--; // subtract one to restart at this line for printing } } else // if month is smaller, we found our date { date_found = true; i--; // subtract one to restart at this line for printing } } else // if year is less, we found our date { date_found = true; i--; // subtract one to restart at this line for printing } } else // if we cannot parse line, move to next position { current_pos++; } // end of finding position to start } else { printContents(); } }// end of for loop // if date_found is still false, set it to true and print last 6 lines if (!date_found) { date_found = true; current_pos -= 7; // current_pos should not be negative if (current_pos < 0) { current_pos = 0; } printContents(); } }