As promised (or threatened?), in this Step, we will add some code. Don’t worry, though, you will just copy-and-paste from here into your app (unless you prefer to type it in yourself), and I will explain along the way what the code is doing.
With the “[Design]” tab of your app active (showing the Windows Form, with the controls we added to it in the last Step on it), 2-click the “Next” Button (circled below).

When you do that, the code portion “behind the form” displays (on the Form1.cs tab). And, by 2-clicking the Button, it caused the Button’s OnClick() event code to be added (although it is empty for now – that is to say, it contains no code within the curly braces). This is how it should look:
private void button1_Click(object sender, EventArgs e)
{
}
What you’re seeing here is the code that will run when the button is clicked. As of now, nothing will happen, as there is nothing between the curly braces, and thus no code to run. This is not really a problem. Having no code doesn’t cause a problem. And it runs very fast. Give yourself a pat on the back if you got that joke. Anyway, onward:
To remedy the “no-code-runs-because-there-is-no-code” problem, add “LoadNextBatch();” between the curly braces so that it looks like this (the new code is bolded):
private void button1_Click(object sender, EventArgs e)
{
LoadNextBatch();
}
You may see an error message now, at the bottom of Visual Studio which says, in effect, that it doesn’t know what LoadNextBatch() is – it doesn’t recognize it. That’s fine; don’t worry about it. It’s because Visual Studio doesn’t know what to make of what you just added. It doesn’t know what “LoadNextBatch()” is yet.
We will take care of that problem now. Follow these steps:
1) Locate the code that looks like this, near the top of the page of code:
public Form1()
{
InitializeComponent();
}
2) Click to the right of the right curly brace (“}”) and hit the Enter key twice. You can now copy-and-paste the code below to where your cursor is (or type it in, if you prefer that).
private void LoadNextBatch()
{
sequence++;
if (sequence == 1)
{
groupBox1.Text = "Select a ROGER";
radioButton1.Text = "EBERT";
radioButton2.Text = "FEDERER";
radioButton3.Text = "MARIS";
}
else if (sequence == 2)
{
groupBox1.Text = "Select a BRUCE";
radioButton1.Text = "HERBELIN-EARLE";
radioButton2.Text = "LEE";
radioButton3.Text = "SPRINGSTEEN";
}
else if (sequence == 3)
{
groupBox1.Text = "Select a SONG";
radioButton1.Text = "DEEP PURPLE";
radioButton2.Text = "SHAPE OF YOU";
radioButton3.Text = "SMOKE ON THE WATER";
}
else if (sequence == 4)
{
groupBox1.Text = "Select a NOVEL";
radioButton1.Text = "1984";
radioButton2.Text = "FRANKENSTEIN";
radioButton3.Text = "THE GOLDFINCH";
}
else if (sequence == 5)
{
groupBox1.Text = "Select a MOVIE";
radioButton1.Text = "FORREST GUMP";
radioButton2.Text = "IT'S A WONDERFUL LIFE";
radioButton3.Text = "WONDER WOMAN";
}
else if (sequence == 6)
{
groupBox1.Text = "Select a TELEVISION SHOW";
radioButton1.Text = "THE DICK VAN DYKE SHOW";
radioButton2.Text = "GAME OF THRONES";
radioButton3.Text = "THE OFFICE";
}
else if (sequence == 7)
{
groupBox1.Text = "Select an AUTHOR";
radioButton1.Text = "DAV PILKEY";
radioButton2.Text = "JOHN GRISHAM";
radioButton3.Text = "MARK TWAIN";
}
else if (sequence == 8)
{
groupBox1.Text = "Select a BAND";
radioButton1.Text = "BENNY GOODMAN";
radioButton2.Text = "GRAND FUNK";
radioButton3.Text = "IMAGINE DRAGONS";
}
else if (sequence == 9)
{
groupBox1.Text = "Select a GIRL'S NAME";
radioButton1.Text = "BRITTANY";
radioButton2.Text = "EMMA";
radioButton3.Text = "GERTRUDE";
}
else if (sequence == 10)
{
groupBox1.Text = "Select a BOY'S NAME";
radioButton1.Text = "HORACE";
radioButton2.Text = "JOHN";
radioButton3.Text = "JOSHUA";
}
}
This is the code that will run when the “Next” button is clicked.
Let’s look at it, and see what it does.
The first line of code is “sequence++;”
What’s happening here is a variable named “sequence” is having its value increased by one. That’s what the “++” does (increases the value of the variable by 1). You might have noticed that you still get an error message at the bottom of the code window. That’s because we haven’t “declared” (added) the sequence variable to our code yet.
Note: A semicolon (;) ends every programming statement in C#. It’s similar to a period in human language, or a “Stop” instruction in an old telegraph message. If you are a couple of hundred years old, you probably remember sending telegraphs. And if so, you are a SuperGeezer. The point is, though, that semicolons are important. Without them, the compiler wouldn’t know when you are finished writing your instruction (in code), and the following bits of code will be “taken out of context” and quite possibly cause the program to be unusable until the semicolon is added. At the very least, the program will do things you weren’t expecting it to do, if you forget to put the semicolons at the end of your programming statements.
So for this to make any sense (to Visual Studio and to us), we must first add the sequence variable.
First, though, I will explain what a “variable” is. A variable is called that because it’s value can vary. That is to say, it can change, such as the temperature can (and does) change. Unlike the weather, though, you can change it. You are not a passive observer, but an active participant.
There are four main things to know about variables:
1) They are of a specific data type (more on this later)
2) You must give them a Name
3) You can assign them values
4) You can retrieve, or access, those values later
So, let’s add this variable. Type int sequence = 0; into your code just below this part:
public partial class Form1 : Form
{
..but above this part:
public Form1()
{
InitializeComponent();
}
In other words, that part of your code (near the top) should now look like this (the new code is bolded):
public partial class Form1 : Form
{
int sequence = 0;
public Form1()
{
InitializeComponent();
}
Do you recall that a variable must have a data type, a name, and that you can assign it a value and later access that value?
The variable named sequence that we just added is of data type “int,” which is short for “integer.” An integer is a number without a fractional element to it. Examples of integers are: -17, 0, 1, 2, 3, … 19, . . ., 42, … 1000000. These are all integers. They are integers as opposed to “real” numbers (with fractions), such as 3.14.
Now that I have mentioned 3.14, I’m hungry for pie. But then again, I’m just about always hungry for pie, so that’s not saying much.

Anyway, as was mentioned, the name of this integer variable is sequence. You can name your variables just about anything. You could name it funkyMonkey or whoopJamboreehoo if you want to, but it’s usually best to keep your variable names short and descriptive, rather than whimsical and frivolous.
The last part of the statement (= 0) is the assignment of the value. It is assigned a value of 0. This isn’t strictly necessary, as an integer has a default value of 0, anyway, but it doesn’t hurt anything and makes it clear what you expect the value to be at the beginning (before you change its value in code).
One last bit of code: We will add the same line of code that we already added to the Button click event also to the Form’s OnLoad() event. In other words, when the form is loaded (when the app starts up),we want it to call the block of code named LoadNextBatch(). To add this code, go back to the “[Design]” tab and 2-click anywhere on the form (but not on a control – on a “blank” area of the form).
This will open the code tab again (Form1.cs) with the following event having been prepared for the adding of code to it:
private void Form1_Load(object sender, EventArgs e)
{
}
Go ahead and add the same code to it that you put in the Button click event code, so that it looks like this (new part bolded):
private void Form1_Load(object sender, EventArgs e)
{
LoadNextBatch();
}
Now the LoadNextBatch() code, which you just added above, will run once when the form loads, and then again every time you click the “Next” button. Each time the LoadNextBatch() block of code runs, the value of the sequence variable is increased by 1 (or, in common programming parlance, it is incremented).
Note: To run the code you write in Visual Studio, either hit the F5 function key at the top of your keyboard, or select the Debug > Start Debugging menu item. If you ever have problems when trying to run your app – that is to say, it doesn’t work right and/or you get error messages, google the text of the error message or describe the problem in your own words in your google search, and you should get an answer on how to fix whatever the problem is. There are simply too many error messages that come up and problems that can (and do) happen to warn you about all of them as we go along. Again, the solution to all of them can be found by googling (and by debugging, but that’s a topic for later). The bad news is that you will have problems with your code; the good news is, it’s nothing to worry about. You can always solve the problem by searching out the reason why it’s happening and then fixing it. It might be a quick, easy fix; but sometimes it’s not. Try not to let the problems frustrate you too much. It happens to everybody, and (just as with life in general) you can overcome the problems, one at a time, if you persevere. See!? Programming can teach you life lessons, too!
In the next Step, we will “keep score” by recording which selections the user makes, and guessing their age (roughly speaking) based on those answers.
Earth-shakingly Important Note: 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. 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). Also, 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).
The audio version of this article can be found here: