Calculating the Area of a Rectangle in Visual Basic 6
When doing Software Design at school, one of my assignments was to create an application that calculated the Area of a rectangle. When I did it, I struggled to find a site that actually helped me, so I¡¯ve made this tutorial for anyone else who may struggle.
- Open Visual Basic 6
- Create a New Form
- Create Three (3) Text boxes
- Select the first box and go to the Properties window
- Change the Name to txtLength
- Select the second box and change the name to txtWidth
- Select the third box and change the name to txtArea
- Create a Button
- Change the Name to cmdButton
- Under the Project menu, right click on Form1 and click View Code
- In the first drop-down box select cmdCalculate
- In the second drop-down box select Click
- You should now see:
- Type the following:
What this code does:
- Creates 3 variables: rec1, rec2, rec3
- These variables have all be defined as Integers (whole numbers)
- Type the following:
What this code does:
- Makes rec1 equal to the value of the text box txtLength
- Makes rec2 equal to the value of the text box txtWidth
- Makes rec3 equal to the value of rec1 multiplied by rec2.
- * is the symbol used for multiplication in Visual Basic (and many other programming languages)
- Now type:

This code simply displays the result of the calculation made in the previous step. - Press the Start button to test your program
Final Result
discuss this topic to forum
