Worksheet 2 - Variables
This worksheet covers three sample applications which illustrate the use of variables - particularly integers and strings. 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 to add two numbers together and show the result as "Answer = ...".
![]() |
|
Example 2
Builds on example 1 to add in a list of the numbers that have been added.
To write this application you will need to work out how to add items to the list box and also clear the items in a list box. As a hint - select the list box in your design mode and press F1 to bring up the help on the MSDN site and then look for sample code or methods which should you how to do this. The code walk through part of the video will show you how to do it however.
This example also uses a "global" variable which is a variable that can be used in more than one function.
![]() |
|
Example 3
This takes the example even further to make a semi-useful calculator.
![]() |
|
If you get through all three examples and are still keen to try more why not try the following:
- Improve the calculator in example 3 to handle real numbers (i.e. so it can take numbers after the decimal point).
- Extend example 2 to be a VAT calculator where it displays two results and two columns - with VAT (at 17.5%) added to one column and result.


