Public Class frmShapes

  'Declare shape array
  Dim shape(3) As Shape

  Private Sub frmShapes_Load(ByVal sender As System.Object,
                             ByVal e As System.EventArgs) Handles MyBase.Load
    'Populate the array with shapes
    shape(0) = New EquilateralTriangle()
    shape(1) = New Square()
    shape(2) = New Pentagon()
    shape(3) = New Hexagon()
  End Sub

  Private Sub btnDisplay_Click(ByVal sender As System.Object,
                               ByVal e As System.EventArgs) Handles btnDisplay.Click
    Dim length As Double
    'Set lengths of all shapes
    length = CDbl(txtLength.Text)
    For i As Integer = 0 To 3
      shape(i).Length = length
    Next
    'Display results
    lstOutput.Items.Clear()
    For i As Integer = 0 To 3
      lstOutput.Items.Add("The " & shape(i).Name & " has area " &
                          FormatNumber(shape(i).Area) & ".")
    Next
  End Sub

End Class     'frmShapes

MustInherit Class Shape
  'Private m_length As Double    'Stores the value of Length property

  Public Property Length() As Double
  '  'Length of a side
  '  Get
  '    Return m_length
  '  End Get
  '  Set(ByVal value As Double)
  '    m_length = value
  '  End Set
  'End Property

  MustOverride Function Name() As String
  'Returns the name of the shape

  MustOverride Function Area() As Double
  'Returns the area of the shape
End Class     'Shape

Class EquilateralTriangle
  Inherits Shape

  Overrides Function Name() As String
    'The name of this shape
    Return "Equilateral Triangle"
  End Function

  Overrides Function Area() As Double
    'Formula for the area of an equilateral triangle
    Return Length * Length * Math.Sqrt(3) / 4
  End Function
End Class     'EquilateralTriangle

Class Square
  Inherits Shape

  Overrides Function Name() As String
    'The name of this shape
    Return "Square"
  End Function

  Overrides Function Area() As Double
    'Formula for the area of a square
    Return Length * Length
  End Function
End Class     'Square

Class Pentagon
  Inherits Shape

  Overrides Function Name() As String
    'The name of this shape
    Return "Pentagon"
  End Function

  Overrides Function Area() As Double
    'Formula for the area of a pentagon
    Return Length * Length * Math.Sqrt(25 + (10 * Math.Sqrt(5))) / 4
  End Function
End Class     'Pentagon

Class Hexagon
  Inherits Shape

  Overrides Function Name() As String
    'The name of this shape
    Return "Hexagon"
  End Function

  Overrides Function Area() As Double
    'Formula for the area of a hexagon
    Return Length * Length * 3 * Math.Sqrt(3) / 2
  End Function

End Class     'Hexagon
