REAL-WORLD COMPUTER PROGRAMMING FOR KIDS
STEP 30: CREATING AND TESTING CSV FILES OF DIFFERENT SIZES, and a Bonus Beauty Treatment for the Form
As solemnly promised, in this Step I will show you how you can create your own lists of Questions and Candidate Answers and add them to this app, providing examples of CSV files that contain both less than 10 and more than 10 sets of Questions and Answers.
Here are the things that need to be done in order to add another CSV file into the mix:
1) Create the CSV file as shown in previous steps. Basically, you simply add, on each line, a Question followed by three Candidate Answers, separating each with a comma. For example, if you wanted to ask the user, “Who was the first famous Rapper?” and give as Candidate Answers “Poe’s Raven,” “MC Hammer,” and “1 SiK pUpPy” you would write on one line in a text file, using an app such as Notepad:
Who was the first famous Rapper?,1 SiK pUpPy, MC Hammer,*Poe’s Raven
A couple of things to notice about this: the Candidate Answers are in alphabetical order. You don’t have to do this, but it’s sensible because it will prevent you from always putting the correct answer in a certain location or using the same pattern over and over (such as putting the correct answer first, then second, then third). By using alphabetical order, the pattern is not predictable and is completely random; you won’t be inadvertently providing a “tipoff” as to which answer is correct or a “tell” (telegraphing what’s going on, so to speak). As for what to select for wrong answers, I suggest going for one that could easily be thought by many to be correct, and one that is simply funny or outrageous. In this example, some may think MC Hammer makes sense; AFAIK, there is no such rapper as “1 SiK pUpPy”; the correct answer may surprise some, too, but note the line from Edgar Allan Poe’s most famous poem (The Raven):
Once upon a midnight dreary, while I pondered, weak and weary,
Over many a quaint and curious volume of forgotten lore—
While I nodded, nearly napping, suddenly there came a tapping,
As of some one gently rapping
, rapping
at my chamber door.
. . .
But the fact is I was napping, and so gently you came rapping
,
And who was this Rapper? The poem goes on to reveal the heretofore secret identity of this mysterious Rapper:
Open here I flung the shutter, when, with many a flirt and flutter,
In there stepped a stately Raven of the saintly days of yore;
So it is proven beyond the shadow of a doubt that Poe’s Raven was the first Rapper (the poem was written in 1845, probably before any of you were born). Poe’s unnamed Raven was the first Rapper -- not “Cool Beans” or “M&Ms” or “Two-pack Shaker” or Lawrence Welk or any of those Pretenders to the Throne.

2) Save the file you have created as a CSV file (give it the .CSV file extension rather than sticking with the default .TXT extension)
3) Verify that you have saved the file in the proper location (where the app is expecting to find it), namely in C:\Programming4Kids. If you already saved it somewhere else, cut and paste it from the current location into there.
Note: Remember to only have commas separating the values, not within the questions or answers themselves. For example, instead of “If Tony had a dog, it would be” you have to omit the comma, like so: “If Tony had a dog it would be” If this bothers you (omitting commas where they grammatically belong), you can change the separator to a semicolon (;) or tilde (~) or something else, but then you would have to change the code where the lines are split on commas. This is ... sorry, we’ve come to that point, finally ... “an exercise left to the reader.”
So to cut to the chase, I have created two (count ‘em, two!) new CSV files and placed them in the proper folder. One has eleven sets of Questions/Answers, and the other has four.
If you want to copy the two files I made rather than create your own, you can copy-and-paste them from below.
Name this first one whatever you want to; maybe “tUbThUmPeR.csv”:
Who was the first famous Rapper?,1 SiK pUpPy, MC Hammer,*Poe’s Raven
What part of your body tells you that your brain is its most important part?,*Your Brain,Your Eohippus,Your Gluteus Maximus
Who had a hit song named "Aqualung"?,Jethro Bodine,*Jethro Tull,The Bodeans
A Flautist:,Flies Airplanes in Alaska,Makes a Lot of Mistakes,*Plays a Flute
Name this one also whatever you want to (but something different than the first one), such as “theRainInSpainFallsMainlyOnTheSheep.csv”:
How is the word that sounds like "Floop-Jizz-a-Wop" actually spelled?,Flupjiczawop,Phloopdcisowab,*There is no such word
If Tony had a dog it would be:,*Tony's dog,Tonys' dog,Tonys dog
If Toe-knee had multiple farms they would be:,Toe-knee's Farm's,Toe-knees Farms',*Toe-knee's Farms
Which is correct?,Whine or Loose,Win or Loose,*Win or Lose
How many years are "four score and seven"?,23,55,*87
What year did Lincoln deliver the Gettysburg Address?,1776,1863,Lincoln didn't have a Gettysburg Address - he was from Illinois
Where was Samuel L. Clemens ("Mark Twain") born?,*Florida (Missouri),Hannibal (Missouri),Pall Mall (Tennessee)
Which is correct?,I have to many chores,*I have too many chores,I have two many chores
"i.e." means:,for example,in extremis,*in other words
"e.g." means:,extra greasy,*for example,in other words
What year did the Mayflower arrive in America?,1520,*1620,1720
The first CSV file (tUbThUmPeR.csv or whatever you named it) has four sets of Questions/Answers; the second CSV file (theRainInSpainFallsMainlyOnTheSheep.csv or whatever you decided, after much gut-wrenching deliberation, to name it) has eleven sets of Questions/Answers.
What should happen is that the file names are read into the Combo Box, as they are in the right place (C:\Programming4Kids) and have the expected file extension (.CSV).
Let’s run the app now and see.
The four files all appear in the Combo Box as they should:

The “Question N of N” Label correctly displays that there are 11 questions, when we select that file:

Also, the correct percentage is computed for each answer:

Why do I say that this rather bizarre number (63.64) is the “correct percentage”? Well, with 10 questions, the final percentage would always be divisible by 10, such as 50%, 80%, 100%, etc., but with an “odd” (both literally and figuratively) number like 11, each answer has a real number as its stepPercentage value. In this case, with eleven questions, each Question counts for a little over 9% (9.09090909091 to be precise), and 9.09090909091 * 7 (or 9.09090909091 X 7) is 63.6363636364, so the math is being done correctly by our app. It is displayed as 63.64 because we earlier limited the number of values past the decimal point to display to 2, and 63.6363636364 rounds to 63.64.
When selecting the other new CSV file -- the one with only 4 sets of Questions/Answers -- we see that it works fine and displays the combination demonstrated at the outset:

So we made it! The app works fine! Yet (sometimes there’s a “Yet”), there is still one thing we could add to make it just a little bit better, namely give the Question Label at the top of the form a different color (other than black) to make it stand out from the rest.
If you’ve noticed (or even if you haven’t, actually), I already did this quite awhile ago without saying anything about it (not wanting to brag), but now I’ll show you how to do it yourself:
1) Select the Form1.cs [Design] tab to show the Form
2) Select the Question Label (lblQuestion)
3) On the Properties Pane, expand the Appearance Section, and find the “ForeColor” property
4) Drop down the ForeColor property (or maybe I should say “Drop up” in this case):

5) From the possibilities presented, select a Color you like, such as “Menu Highlight”:

In the next Step in our Journey, we will add try...catch blocks everywhere in the code, and incorporate Logging as another handy way to debug our app when it is not behaving as we intend it to -- Until then!

The first volume of my four-volume series, Real-World Computer Programming for Kids of All Ages, namely Volume 1: Windows Forms Apps Using C# and Visual Studio is now available in both Paperback and Kindle formats. Volume 1 contains everything that has been printed in this Newsletter so far and through Step 34.
The kindle version of the book can be accessed here: https://www.amazon.com/dp/B08H7DKKCS/ and the Paperback version can be accessed here https://www.amazon.com/dp/B08H9RB1WG/

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: