Function Math Geometry Class

VolumeCalc

"Volume Calculator" Calculate the Volume of some type of shape given certain other properties of the shape.

Signature (Visual Basic / VBA)

Public Function VolumeCalc( _
      Optional ByVal vShape As Variant _
    , Optional ByVal vBaseOrRadius As Variant _
    , Optional ByVal vHeightOrRadius2 As Variant _
    , Optional ByVal vDepthOrTop As Variant _
    ) As Variant

Code Example

    VolumeCalc("Cone", 2, 3) = 12.5663706143592
    VolumeCalc("Cone", 2, 4) = 16.7551608191456
    VolumeCalc("Cylinder", 2, 3) = 37.6991118430775
    VolumeCalc("Cylinder", 2, 4) = 50.2654824574367
    IsNull(VolumeCalc("Unknown", 2, 3, 4)) = True

Parameters

Parameter Description
vShape Name of the geometric shape whose volume is being calculated. Function returns Null if vShape is Null or cannot be fixed up to a String. The shape must be one of those detailed below. This name is case-insensitive, so for example, the names "CUBE" and "Cube" match each other.
vBaseOrRadius The base or (first) radius of the shape. This value should be a number if it is known. If this value is not applicable to the shape, it should be missing or Null.
vHeightOrRadius2 The height or second radius of the shape. This value should be a number if it is known. If this value is not applicable to the shape, it should be missing or Null.
vDepthOrTop The depth or top of the shape. This value should be a number if it is known. If this value is not applicable to the shape, it should be missing or Null.

Notes & Version History

Details The meaning of each argument and the arguments that must be provided differ depending upon the shape whose area is to be calculated. See the details below which describe the properties that must be passed for each type of shape.
Note Function may return a complex number in the form of a string if the given dimensions are not consistent with the shape.
Cone Requires Radius (of the base) in vBaseOrRadius. Requires Height in vHeightOrRadius2.
Cube Requires Base in vBaseOrRadius.
Cylinder Requires Radius in vBaseOrRadius. Requires Height in vHeightOrRadius2.
Pipe Requires (smaller) Radius in vBaseOrRadius. Requires (larger) Radius in vHeightOrRadius2. Note: Radius #1 should be smaller than Radius #2.
Pyramid Requires Base in vBaseOrRadius. Requires Height in vHeightOrRadius2. Requires Depth in vDepthOrTop.
Rectangular Solid Requires Base in vBaseOrRadius. Requires Height in vHeightOrRadius2. Requires Depth in vDepthOrTop.
Sphere Requires Radius in vBaseOrRadius.
Torus Requires (smaller) Radius in vBaseOrRadius. Requires (larger) Radius in vHeightOrRadius2. Note: Radius #1 should be smaller than Radius #2.