\'Write a program to calculate Area, Parameter & Volume of
\'a)Rectangle
\'b)Square
\'c)Circle
\'Use
\'a)While/Wend (Do While/Loop)
\'b)InputBox
\'c)Const
\'Features:
\' Have Startup Form
\' Have 3 options or types to calculate, Rectangle, Square, and Circle
\' Calculate Area, Perimeter and Volume for each shape
\' Clear button and Exit button
\' Detect error for no input, when button cancel pressed
\'Known bug:
\' Didn\'t deal with enough error yet
Option Explicit
Const pi As Single = 3.142
Dim Area As Single
Dim Perimeter As Single
Dim Volume As Single
Dim Counter As Boolean
Dim CounterString As String
Dim inputTest As String
Private Sub cmdClear_Click()
lblDisplayArea.Caption = ""
lblDisplayPerimeter.Caption = ""
lblDisplayVolume.Caption = ""
Area = 0
Perimeter = 0
Volume = 0
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdRectangle_Click()
Counter = True
Do While Counter = True
Dim L As Single \'Length
Dim H As Single \'Height
Dim W As Single \'Width
LOOP1:
inputTest = InputBox("Enter length of the Rectangle", "Input Length Rectangle")
If IsNumeric(inputTest) = True Then
L = inputTest
ElseIf inputTest = "" Then
MsgBox ("You pressed Cancel or no input")
GoTo Canceled
Else
MsgBox ("Please enter a number")
GoTo LOOP1
End If
LOOP2:
inputTest = InputBox("Enter height of the Rectangle", "Input Height Rectangle")
If IsNumeric(inputTest) = True Then
H = inputTest
ElseIf inputTest = "" Then
MsgBox ("You pressed Cancel or no input")
GoTo Canceled
Else
MsgBox ("Please enter a number")
GoTo LOOP2
End If
LOOP3:
inputTest = InputBox("Enter width of the Rectangle", "Input Width Rectangle")
If IsNumeric(inputTest) = True Then
W = inputTest
ElseIf inputTest = "" Then
MsgBox ("You pressed Cancel or no input")
GoTo Canceled
Else
MsgBox ("Please enter a number")
GoTo LOOP3
End If
Area = L * H
Perimeter = 2 * L + 2 * H
Volume = L * H * W
lblDisplayArea.Caption = Area
lblDisplayPerimeter.Caption = Perimeter
lblDisplayVolume.Caption = Volume
CounterString = InputBox("Do you want to calculate again?", "Calculate Again?")
If CounterString = "Y" Then
Counter = True
Else:
Counter = False
End If
Loop
Canceled:
End Sub
Private Sub cmdSquare_Click()
Counter = True
While Counter = True
Dim S As Single \'Sides
LOOP4:
inputTest = InputBox("Enter side of the Square", "Input Side Square")
If IsNumeric(inputTest) = True Then
S = inputTest
ElseIf inputTest = "" Then
MsgBox ("You pressed Cancel or no input")
GoTo Canceled
Else
MsgBox ("Please enter a number")
GoTo LOOP4
End If
Area = S * S
Perimeter = 4 * S
Volume = S * S * S
lblDisplayArea.Caption = Area
lblDisplayPerimeter.Caption = Perimeter
lblDisplayVolume.Caption = Volume
CounterString = InputBox("Do you want to calculate again?", "Calculate Again?")
If CounterString = "Y" Then
Counter = True
Else:
Counter = False
End If
Wend
Canceled:
End Sub
Private Sub cmdCircle_Click()
Counter = True
While Counter = True
Dim R As Single \'Radius
LOOP5:
inputTest = InputBox("Enter radius of the Circle", "Input Radius Circle")
If IsNumeric(inputTest) = True Then
R = inputTest
ElseIf inputTest = "" Then
MsgBox ("You pressed Cancel or no input")
GoTo Canceled
Else
MsgBox ("Please enter a number")
GoTo LOOP5
End If
Area = pi * R * R
Perimeter = 2 * pi * R
Volume = 4 / 3 * pi * R * R * R
lblDisplayArea.Caption = Area
lblDisplayPerimeter.Caption = Perimeter
lblDisplayVolume.Caption = Volume
CounterString = InputBox("Do you want to calculate again?", "Calculate Again?")
If CounterString = "No" Or CounterString = "no" Or CounterString = "NO" Or CounterString = "N" Or CounterString = "n" Then
Counter = False
Else:
Counter = True
End If
Wend
Canceled:
End Sub