Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
395 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
| Software ==> | Visual Basic (46 exercises) |
| Topic ==> | Creating classes (4 exercises) |
| Level ==> | Harder than average |
| Subject ==> | Visual Basic training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
Right-click on your project in Solution Explorer and choose to add the form from the above folder (you can alternatively press SHIFT + ALT + A ).
When you set this to be your start-up form and run your application, you should see this:

You should see a form containing 18 greyed out owls, with only the Deal button enabled.
When you click on the Deal button, your system should randomly assign 9 owl pictures to get something like this:

Each time you "deal" the owls you'll get a different combination.
When you click on the Start button, you can start playing:

Here someone has already guessed 3 pairs, but the fourth guess at the bottom right is wrong, and the unmatched pair will revert back to grey in a second.
When a user has detected all of the pairs, your system should show a congratulatory message then close down the form. Your task is to add code to this form so that you can play pairs!
To start with, the 9 owl pictures that you'll need are in the folder above. To add them, right-click on your project to show its properties, click on the Resources tab (as below) then add your existing image files:

Select the menu option shown to add images to your project.
Visual Studio should add the images that you select, and give them names:

The images are added to a folder called Resources.
You can assign an image to a button in code like this:
' show an owl on a button
Dim b As Button = CType(sender, Button)
b.Image = My.Resources.owl1
In this example, we convert the sender of the event to a button, then change its Image property to be the resource called owl1.
You can use the Tag property of each button to keep track of which image is assigned to it (this property isn't used for any other purpose).
At some stage you'll need to loop over all the buttons, doing something to each. Here's one way to do this (this example would remove the image from every button):
' remove images from all buttons
Dim i As Integer
For i = 1 To 18
Dim b As Button = CType(Me.Controls("Button" + i.ToString), Button)
b.Image = Nothing
Next i
There's no right or wrong way to write the classes for this project, but the answer uses the following two classes:
| Class | How used |
|---|---|
| PairButton | Used to refer to each button |
| PairTurn | Use for a single turn (ie the action of choosing two pictures). |
After an unsuccessful guess, you'll want to hide the two buttons chosen. One command to wait a second to give your user time to view the choices they've made would be:
' if not a match, hide both after a bit of a wait
System.Threading.Thread.Sleep(1000)
To ensure that you don't allocate more than two owls to any combination of buttons initially, the system uses this variable:
'holds unassigned buttons
OwlsLeft = "112233445566778899"
There are many more elegant ways to do this, without doubt, and you should feel free to use one of them if you can think of it!
And with all these hints - good luck!
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2026. All Rights Reserved.