document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. \'Write a program to calculate Area, Parameter & Volume of
  2. \'a)Rectangle
  3. \'b)Square
  4. \'c)Circle
  5. \'Use
  6. \'a)While/Wend (Do While/Loop)
  7. \'b)InputBox
  8. \'c)Const
  9.  
  10. \'Features:
  11. \'   Have Startup Form
  12. \'   Have 3 options or types to calculate, Rectangle, Square, and Circle
  13. \'   Calculate Area, Perimeter and Volume for each shape
  14. \'   Clear button and Exit button
  15. \'   Detect error for no input, when button cancel pressed
  16. \'Known bug:
  17. \'   Didn\'t deal with enough error yet
  18. Option Explicit
  19. Const pi As Single = 3.142
  20. Dim Area As Single
  21. Dim Perimeter As Single
  22. Dim Volume As Single
  23. Dim Counter As Boolean
  24. Dim CounterString As String
  25. Dim inputTest As String
  26.  
  27. Private Sub cmdClear_Click()
  28.     lblDisplayArea.Caption = ""
  29.     lblDisplayPerimeter.Caption = ""
  30.     lblDisplayVolume.Caption = ""
  31.     Area = 0
  32.     Perimeter = 0
  33.     Volume = 0
  34. End Sub
  35.  
  36. Private Sub cmdExit_Click()
  37.     End
  38. End Sub
  39.  
  40. Private Sub cmdRectangle_Click()
  41.     Counter = True
  42.     Do While Counter = True
  43.    
  44.     Dim L As Single \'Length
  45.    Dim H As Single \'Height
  46.    Dim W As Single \'Width
  47. LOOP1:
  48.     inputTest = InputBox("Enter length of the Rectangle", "Input Length Rectangle")
  49.     If IsNumeric(inputTest) = True Then
  50.             L = inputTest
  51.     ElseIf inputTest = "" Then
  52.             MsgBox ("You pressed Cancel or no input")
  53.             GoTo Canceled
  54.     Else
  55.             MsgBox ("Please enter a number")
  56.             GoTo LOOP1
  57.     End If
  58. LOOP2:
  59.     inputTest = InputBox("Enter height of the Rectangle", "Input Height Rectangle")
  60.     If IsNumeric(inputTest) = True Then
  61.             H = inputTest
  62.     ElseIf inputTest = "" Then
  63.             MsgBox ("You pressed Cancel or no input")
  64.             GoTo Canceled
  65.     Else
  66.             MsgBox ("Please enter a number")
  67.             GoTo LOOP2
  68.     End If
  69. LOOP3:
  70.     inputTest = InputBox("Enter width of the Rectangle", "Input Width Rectangle")
  71.     If IsNumeric(inputTest) = True Then
  72.             W = inputTest
  73.     ElseIf inputTest = "" Then
  74.             MsgBox ("You pressed Cancel or no input")
  75.             GoTo Canceled
  76.     Else
  77.             MsgBox ("Please enter a number")
  78.             GoTo LOOP3
  79.     End If
  80.     Area = L * H
  81.     Perimeter = 2 * L + 2 * H
  82.     Volume = L * H * W
  83.    
  84.     lblDisplayArea.Caption = Area
  85.     lblDisplayPerimeter.Caption = Perimeter
  86.     lblDisplayVolume.Caption = Volume
  87.    
  88.     CounterString = InputBox("Do you want to calculate again?", "Calculate Again?")
  89.     If CounterString = "Y" Then
  90.         Counter = True
  91.     Else:
  92.         Counter = False
  93.     End If
  94.     Loop
  95. Canceled:
  96. End Sub
  97.  
  98. Private Sub cmdSquare_Click()
  99.     Counter = True
  100.     While Counter = True
  101.     Dim S As Single \'Sides
  102. LOOP4:
  103.     inputTest = InputBox("Enter side of the Square", "Input Side Square")
  104.     If IsNumeric(inputTest) = True Then
  105.             S = inputTest
  106.     ElseIf inputTest = "" Then
  107.             MsgBox ("You pressed Cancel or no input")
  108.             GoTo Canceled
  109.     Else
  110.             MsgBox ("Please enter a number")
  111.             GoTo LOOP4
  112.     End If
  113.    
  114.     Area = S * S
  115.     Perimeter = 4 * S
  116.     Volume = S * S * S
  117.    
  118.     lblDisplayArea.Caption = Area
  119.     lblDisplayPerimeter.Caption = Perimeter
  120.     lblDisplayVolume.Caption = Volume
  121.     CounterString = InputBox("Do you want to calculate again?", "Calculate Again?")
  122.     If CounterString = "Y" Then
  123.         Counter = True
  124.     Else:
  125.         Counter = False
  126.     End If
  127.     Wend
  128. Canceled:
  129. End Sub
  130.  
  131. Private Sub cmdCircle_Click()
  132.     Counter = True
  133.     While Counter = True
  134.         Dim R As Single \'Radius
  135. LOOP5:
  136.         inputTest = InputBox("Enter radius of the Circle", "Input Radius Circle")
  137.  
  138.         If IsNumeric(inputTest) = True Then
  139.             R = inputTest
  140.         ElseIf inputTest = "" Then
  141.                 MsgBox ("You pressed Cancel or no input")
  142.                 GoTo Canceled
  143.         Else
  144.                 MsgBox ("Please enter a number")
  145.                 GoTo LOOP5
  146.         End If
  147.         Area = pi * R * R
  148.         Perimeter = 2 * pi * R
  149.         Volume = 4 / 3 * pi * R * R * R
  150.        
  151.         lblDisplayArea.Caption = Area
  152.         lblDisplayPerimeter.Caption = Perimeter
  153.         lblDisplayVolume.Caption = Volume
  154.         CounterString = InputBox("Do you want to calculate again?", "Calculate Again?")
  155.         If CounterString = "No" Or CounterString = "no" Or CounterString = "NO" Or CounterString = "N" Or CounterString = "n" Then
  156.             Counter = False
  157.         Else:
  158.             Counter = True
  159.         End If
  160.     Wend
  161. Canceled:
  162. End Sub
  163.  
  164.  
');