WISE OWL EXERCISES
VISUAL BASIC EXERCISES
VISUAL BASIC EXERCISES
- Drawing forms (2)
- Form events (1)
- Variables and data types (2)
- Enumerations and constants (2)
- Form validation (3)
- Menus and toolbars (2)
- Files and folders (1)
- Basic DataGridViews (1)
- Reacting to DataGridView events (3)
- Advanced DataGridViews (2)
- Creating classes (4)
- Coding in VB.NET (2)
- Variables and constants (3)
- Testing conditions (2)
- Passing arguments (3)
- Using arrays (2)
- Loops (2)
- Working with files (3)
- Lists (3)
- Creating properties (3)
Visual Basic | Variables and constants exercise | Get the Add button to work in a basic calculator
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.
You can learn how to do this exercise on the relevant Wise Owl classroom training course (sadly for the moment only in the UK).
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
To avoid having to draw the form needed by this exercise, right-click on the name of your project in Solution Explorer then choose Add --> Existing Item... (you can also press CTRL + D to do the same thing).
Choose only the file called frmCalculator.cs in the above folder to import it into your project, then make this the default form. When you run your application, you should now see a simple calculator form.
Attach code to the Calculate button. Begin with a Try ... Catch clause to check that you can read the two numbers entered into integer variables:
Your error-trapping should exit the subroutine if a user has entered anything but whole numbers into either of the two input boxes.
If on the other hand you have a sensible user, he or she should see the sum of the two integers entered:
What you should see if you enter genuine numbers in the two boxes; the correct answer at the bottom of the form.
Close down any forms that you have left open.