Area Calculator

12 points

Setting up the Form

Add a ListBox and a Label to the form, on the left side. Rename the ListBox 'lstShapes'. Edit the ListBox and add three 2D shapes and one 3D shape. One of the 2D shapes should be a Circle.

In the middle of the form, add 3 Labels and 3 TextBoxes. This is where the user will enter the dimensions of a shape.

To the right of the form, add a Button and change its Text property to 'Find Result' or something similar. Add 2 Labels. Rename one 'lblHeading' and the other 'lblResult'.

Here is what my program looks like when it is running:

Writing the Code

Double-click on 'lstShapes' and you'll be writing the method Private Sub lstShapes_SelectedIndexChanged.
- In this method, set the Visible properties of Label2, Label3, TextBox2 and TextBox3 (in the middle of the form) to True.
- Clear the 3 TextBoxes, 'lblHeading' and 'lblResult' by setting their Text Property equal to " ".
- When the user clicks on a shape in the ListBox, it sets the 'selectedItem' property of 'lstShapes'. You can use this to set up an IF - ELSEIF statement, which can begin:
If lstShapes.SelectedItem = "Triangle" Then
Inside each branch of the IF statement, adjust Label1, Label2 and Label3. Also, make invisible any Labels and TextBoxes that won't be needed for a given shape. And set 'lblHeading.Text' to read 'Area of Triangle:' or something similar.

Double-click on the button and you'll be writing the method Private Sub Button1_Click.
- In this method, declare 'Area' as a Double.
- Set up an IF - ELSEIF statement, similar to the one in the method above. Inside each branch of the IF statement, use the numbers in the TextBoxes to find the shape's area, and assign it to 'Area'. Use CDbl to convert a TextBox to a Double: CDbl(TextBox1.Text). After the IF statement ends, assign 'Area' to 'lblResult'.

Demo

You can download my version of this program here (shapes.zip), to get an idea of what your program will do when it is complete.