Worksheet 3 - Conditionals
This worksheet covers three sample applications which illustrate the use of conditionals. Watch the videos to see how the applications should work then pause the video when you get to "Now Build It" and have a go at building it before you watch the walk through of how the code is written.
Note that the video player has a "make full screen" button in the bottom right. You'll want to use this when the video starts showing you the code walk through.
Example 1
A simple application which uses a conditional to check if an answer is right once it is typed in. To do this example you'll need to know the following:
- A text box has a "TextChanged" event which is called every time the text in it changes. You need to use this as there's no button in this example to put your code behind. To add this event handler to your program simply double-click the text box.
- You use If...Then...Else...End If to check the value entered in the box.
![]() |
|
Example 2
This is a more complicated example which generates a random number which you have to guess. The computer tells you whether you're guess is high, low or right and how many tries you've had.
To write this program you'll need to know the following.
To generate a random number you need to create a new Random object as follows:
Dim rnd As New Random
You then generate the random number like this:
answer = rnd.Next(50) + 1
Which generates a random number from 0 to 49 (adding 1 to it to make it between 1 and 50).
You will also need to use the form Load event to initialise the variables (double click the form itself to add this).
![]() |
|
Example 3
This example introduces the Select Case....Case...End Select construct by implementing the rock, paper,scissors game.
![]() |
|
If you get through both these examples and are still keen to try more why not try the following:
- Extend example 2 so that you can choose to have another game.
- Extend example 3 so that the text label prompts the user to have another go.


