# Overview

This is a surface areas and volumes calculator, that works with Rectangles, Cuboids, Circles, Cylinders, Spheres, Triangles, Cones, and regular four sided Pyramids.

In this example, I've reused my extended DGV Control (see Other Resources), and also a Rounding Control I've used in previous projects. I used DGVs to allow finding areas and volumes for complex shapes by breaking them down into component shapes. For example, you could calculate the surface area of a house.

The extended DGV is bound to a Datatable, which i originally intended to use more extensively, but it's only used for calculating values from formatted strings in this finished version. The formulas for areas and volumes are all stored in a Form level List(Of Class). On selecting a shape, the relevant List member is stored in the DGV row's Tag property, for easy retrieval. To calculate an area (and also a volume for 3D shapes), you just need to select a shape from the Combobox, then complete the indicated fields. The area and volume DGVs are updated on cell validation.

# The item Class and the List(Of item)

This is the item Class:

Public Class item

Public text As String

Public areaFormula As String

Public areaFormula1 As String

Public volumeFormula As String

Public volumeFormula1 As String

End Class

This is the List(Of item) that contains all of the formulas used in this calculator:

Dim items As New List(Of item)(New item() {New item With {

.text = "Rectangle",

.areaFormula = "l * w",

.areaFormula1 = "{0} * {1}"},

New item With {

.text = "Cuboid",

.areaFormula = "(l * w * 2) + (l * h * 2) + (w * h * 2)",

.areaFormula1 = "({0} * {1} * 2) + ({0} * {2} * 2) + ({1} * {2} * 2)",

.volumeFormula = "l * w * h",

.volumeFormula1 = "{0} * {1} * {2}"},

New item With {

.text = "Circle",

.areaFormula = "PI * r^2",

.areaFormula1 = "{5} * {3} * {3}"},

New item With {

.text = "Cylinder",

.areaFormula = "2 * PI * r * h + 2 * PI * r^2",

.areaFormula1 = "2 * {5} * {3} * {2} + 2 * {5} * {3} * {3}",

.volumeFormula = "PI * r^2 * h",

.volumeFormula1 = "{5} * {3} * {3} * {2}"},

New item With {

.text = "Sphere",

.areaFormula = "4 * PI * r^2",

.areaFormula1 = "4 * {5} * {3} * {3}",

.volumeFormula = "(4/3) * PI * r^3",

.volumeFormula1 = "(4/3) * {5} * {3} * {3} * {3}"},

New item With {

.text = "Triangle",

.areaFormula = "1/2 * b * h",

.areaFormula1 = "1/2 * {4} * {2}"},

New item With {

.text = "Cone",

.areaFormula = "PI * r * (r + SQRT(h^2 + r^2))",

.areaFormula1 = "{5} * {3} * ({3} + SQRT({2} * {2} + {3} * {3}))",

.volumeFormula = "PI * r^2 * (h/3)",

.volumeFormula1 = "{5} * {3} * {3} * ({2}/3)"},

New item With {

.text = "Pyramid",

.areaFormula = "b^2 + 2 * b * SQRT(h^2 + b^2 / 4)",

.areaFormula1 = "{4} * {4} + 2 * {4} * SQRT({2} * {2} + {4} * {4} / 4)",

.volumeFormula = "(b^2 * h) / 3",

.volumeFormula1 = "({4} * {4} * {2}) / 3"}})

extended dgv