One step at a time, you are learning “real-world” programming. Part of that is actually called “Stepping.” You step through code, in the debugger, with a weather eye and a wary watch on just what’s happening inside your code (which is not always what you think or expect is happening).
Stepping through your code is not a trip through “The Fire Swamp,” though.
Note: If you haven’t seen the movie The Princess Bride yet, take a break now and enjoy yourself for a bit. Tell whoever is monitoring your progress in these Steps that your Guide (I guess that’s a good enough “title” for me in this role) highly recommended that you do so. Or, you could wait until later. But watch it, anyway, some time.
Anyway, be doubly assured that this trip is no “Fire Swamp” type of experience. It is more like a “walk in the park,” like the one this cat is taking:

A.Savin (Wikimedia Commons · WikiPhotoSpace) / FAL
As we step through the code, there is a method to our madness (no pun intended). That is to say, there is something specific we are looking for. There is a bug in our logic somewhere. Maybe more than one. The problem right now in our code is that when you go from answering Question #9 to the 10th and final question (by clicking the “Next” button), the “Question N of N” Label goes from “Question 9 of 10” to “Question 11 of 10” (it should, of course, be “Question 10 of 10”). Also, after 9 questions have been answered, it shows the percentage of correct answers as being 70% - which is impossible with 9 questions. It can only legitimately be 0, 11, 22, 33, 44, 56, 67, 78, 89, or 100% -- not 70. So we will step through the code to see what the problem is (or problems are).
There may be another bug, too, but fixing the first ones may solve that one, also. It is this: Selecting the next CSV file from the Combo Box does not refresh the screen – all Labels and Radio Button Text remains the same (it should set the Progress Bar back to 0, the “Question N of N” to “Question 1 of 10”, the percentage back to a simple, non-committal “%” and display the first Question in the top Label and the first three Candidate Answers in the Radio Buttons.
As mentioned in the previous Step, not all of the stuff that appears in the code listing actually runs; that is to say, not all of it can be stepped through, line-by-line, at run-time as we are debugging. For example, the variable and const declarations, the names of the methods and event handlers (their “definitions”), the using clauses at the top of the file, the curly braces that enclose blocks of code – those sorts of things are not “steppable.” They matter. They are necessary. But you can’t step through them (nor would you want to, because it would be of no value to do so).
I’m going to show the code one more time, the difference being this time I will not show anything that doesn’t actually run (which are the things just mentioned in the previous paragraph). And when one method calls another, the code from the called method is in place right there, inline, so the true path through the code is seen. This is the path the debugger will take through the maze as we step through the code.
So here’s that code, and then we’ll begin to step through it:
// FormLoad event:
originalQuestionNofN = lblQuestionNOfN.Text;
originalPercentageStr = lblPercentage.Text;
// Combo Box DropDown Event – fires when user selects the Combo Box
if (cmbxSelectMultiChoiceFile.Items.Count > 0) return;
fileNames = GetFileNames(pathToSearch);
// GetFileNames method – called inline from the Combo Box Drop Down Event
string[] _fileNames;
_fileNames = Directory.GetFiles(pathToSearch, "*.csv");
return _fileNames;
// ....back to the Combo Box DropDown Event
foreach (string file in fileNames)
cmbxSelectMultiChoiceFile.Items.Add(file);
// SelectedIndexChanged event of the ComboBox – fires when user selects a File from the ComboBox
selectedFile = cmbxSelectMultiChoiceFile.SelectedItem.ToString();
if (mccList is null)
mccList = new List<MultipleChoiceClass>();
else
mccList.Clear();
lblQuestionNOfN.Text = originalQuestionNofN;
lblPercentage.Text = originalPercentageStr;
progressBar1.Value = 0;
fileStrArray = File.ReadAllLines(selectedFile, Encoding.UTF8);
numberOfQuestions = fileStrArray.Length;
stepPercentage = 100 / numberOfQuestions;
stepAmount = (int)Math.Round(stepPercentage);
foreach (string line in fileStrArray)
string[] subPhrases = line.Split(',');
mcc = new MultipleChoiceClass();
mcc.Question = subPhrases[QUESTION];
mcc.CandidateAnswer1 = subPhrases[CANDIDATEANSWER1];
mcc.CandidateAnswer2 = subPhrases[CANDIDATEANSWER2];
mcc.CandidateAnswer3 = subPhrases[CANDIDATEANSWER3];
if (mcc.CandidateAnswer1.Contains("*"))
mcc.CorrectAnswer = 1;
mcc.CandidateAnswer1 = mcc.CandidateAnswer1.Substring(1);
else if (mcc.CandidateAnswer2.Contains("*"))
mcc.CorrectAnswer = 2;
mcc.CandidateAnswer2 = mcc.CandidateAnswer2.Substring(1);
else if (mcc.CandidateAnswer3.Contains("*"))
mcc.CorrectAnswer = 3;
mcc.CandidateAnswer3 = mcc.CandidateAnswer3.Substring(1);
mccList.Add(mcc);
LoadNextBatch();
// LoadNextBatch method – called inline from the end of the Selected Index Changed event of the Combo Box
MultipleChoiceClassIndex++;
freezeAnswer = MultipleChoiceClassIndex + 1 == numberOfQuestions;
btnNext.Enabled = false;
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
UpdateQuestionNumberLabel();
// UpdateQuestionNumberLabel method called inline from the LoadNextBatch method
lblQuestionNOfN.Text = string.Format(baseQNOfN, currentQuestionNumber, numberOfQuestions);
// ...back to the LoadNextBatch method
if (progressBar1.Value < progressBar1.Maximum)
progressBar1.Value = questionsAnswered * stepAmount;
if (MultipleChoiceClassIndex < numberOfQuestions)
lblQuestion.Text = mccList[MultipleChoiceClassIndex].Question;
radioButton1.Text = mccList[MultipleChoiceClassIndex].CandidateAnswer1;
radioButton2.Text = mccList[MultipleChoiceClassIndex].CandidateAnswer2;
radioButton3.Text = mccList[MultipleChoiceClassIndex].CandidateAnswer3;
// “catch” code
MessageBox.Show(ex.Message);
throw;
// ...back to the SelectedIndexChanged event of the Combo Box
catch (Exception ex)
MessageBox.Show(ex.Message);
throw;
// CheckedChanged Event Handler of the Radio Buttons (shared among all of them) – called when the user clicks one of the Radio Buttons
if (freezeAnswer)
questionsAnswered = numberOfQuestions;
UpdatePercentageCorrect();
// UpdatePercentageCorrect method called inline from the CheckedChanged Event Handler of the Radio Buttons
if (AnswerIsCorrect())
// AnswerIsCorrect method called inline from the UpdatePercentageCorrect method
correctAnswer = mccList[MultipleChoiceClassIndex].CorrectAnswer;
if (radioButton1.Checked)answerSelected = 1;
else if (radioButton2.Checked)answerSelected = 2;
else if (radioButton3.Checked)answerSelected = 3;
return (answerSelected == correctAnswer);
// ...back to UpdatePercentageCorrect method
correctAnswers++;
percentageCorrect = (Convert.ToDouble(correctAnswers) /
Convert.ToDouble(questionsAnswered)) * 100;
lblPercentage.Text = percentageCorrect.ToString() + "%";
progressBar1.Value = questionsAnswered * stepAmount;
// ...back to CheckedChanged Event Handler of the Radio Buttons
btnNext.Enabled = false;
return;
btnNext.Enabled = (sender as RadioButton).Checked;
// Click event of the “Next” Button – fires when the user selects the “Next” Button
if (questionsAnswered < numberOfQuestions)
questionsAnswered++;
UpdatePercentageCorrect();
// UpdatePercentageCorrect method called inline from the Click event of the “Next” Button
if (AnswerIsCorrect())
// AnswerIsCorrect method called inline from the AnswerIsCorrect method (same as shown above)
correctAnswer = mccList[MultipleChoiceClassIndex].CorrectAnswer;
if (radioButton1.Checked) { answerSelected = 1; }
else if (radioButton2.Checked) { answerSelected = 2; }
else if (radioButton3.Checked) { answerSelected = 3; }
return (answerSelected == correctAnswer);
// ...back to UpdatePercentageCorrect method (same as shown above)
correctAnswers++;
percentageCorrect = (Convert.ToDouble(correctAnswers) /
Convert.ToDouble(questionsAnswered)) * 100;
lblPercentage.Text = percentageCorrect.ToString() + "%";
progressBar1.Value = questionsAnswered * stepAmount;
// ...back to Click event of the “Next” Button
if (questionsAnswered == numberOfQuestions)return;
LoadNextBatch();
Then LoadNextBatch continues the cycle...
Are you ready to venture forth into the maze?

Photo by Dennis Jarvis from Halifax, Canada / CC BY-SA (https://creativecommons.org/licenses/by-sa/2.0)
Remember that we are specifically looking for the reason why the “Question N of N” Label goes from “9 of 10” to “11 of 10” and why 70% is displayed as a correct answer percentage after 9 Questions, which is mathematically impossible.
So to find that bug or those bugs (that is to say, to determine what is causing these failures), we will step through the code by putting a breakpoint in the “Next” button’s Click event, and then continue to select the F10 key to step over lines of code within that Event Handler, and F11 when we reach calls to other methods.
Note: F10 steps over the line of code, after which you can see what assignment was made (if any) on the line you just stepped over. F11 will temporarily leave the current method and step into the method being called, from which point you can go back to using F10 to step through those lines -- unless that method calls yet another method, and then you select F11 again to step into that method.
It sounds more complicated than it really is, perhaps. We will take up with the process in the next Step, illuminating what happens when, and why. Together we will detective out these bugs!

Until then!
Earth-shakingly Important Notice: If you have a basic programming question (suitable to an audience of “Kids”), send it to idiolectable@gmail.com, specifying whether you would like your name and location used if it is printed in a future “Step” of this newsletter. If you are a subscriber to the newsletter, you can also leave a question at the bottom of this Step, in the “Comments” section.
If you do not want to give your real name, a nickname is acceptable (the first “Letter to the Editor” of mine that was printed appeared in Rolling Stone magazine, back in the early 1970s, and I signed it “Sylvester” for some reason which I no longer remember).
Finally, it’s always interesting to see where people are from, so please provide your City or Town and the State it’s in, too (or Province, or whatever the region where you live is called).
To listen to this Step, the audio of it can be found here: