Preview

Perimeter and Area Program Foe Visual Basic

Good Essays
Open Document
Open Document
305 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Perimeter and Area Program Foe Visual Basic
* * * *
I have to create a Visual Basic form that accepts the length and width of a rectangle from the user and...? then calculates the area and perimeter of the rectangle. I am really new to programming and don't understand much of the coding yet. The teacher is very hard to learn from. Can somebody please help me?? * 2 years ago * Report Abuse
Additional Details
Operation
· The user enters values for the length and width of a rectangle and clicks the Calculate button or presses the Enter key to activate that button.
· The application then displays the area and perimeter of the rectangle in the third and fourth labels on the right side of the form.
Specifications

· The formula for calculating the area is width * length.
· The formula for calculating the perimeter is 2 * width + 2 * length.
· The application should accept fractional decimal entries like 10.5 and 20.65.
· Assume that the user will enter valid numeric data for the length and width.
2 years ago garbo744... Best Answer - Chosen by Voters
Assuming:

The Form is named Form1
The textbox for length is named Textbox1
The textbox for width is named Textbox2
The label for area is named Label1
The label for perimeter is named Label2

Then the macro for the 'Calculate' button would be

Sub Results()
Form1.Label1.Value = Textbox1.Value * Textbox2.Value
Form1.Label2.Value = 2 * Textbox1.Value + 2 * Textbox2.Value
End Sub

If you want to get a little more creative:

Sub Results()
If Form1.Textbox1.Value = "" Then
Msgbox "Please enter a Length",VbOkOnly, "Invalid Entry"
Form1.Textbox1.Setfocus
Exit Sub
End If
If Form1.Textbox2.Value = "" Then
Msgbox "Please enter a Width",VbOkOnly, "Invalid Entry"
Form1.Textbox1.Setfocus
Exit Sub
End If
Form1.Label1.Value = Textbox1.Value * Textbox2.Value
Form1.Label2.Value = 2 * Textbox1.Value + 2 * Textbox2.Value
End

You May Also Find These Documents Helpful