HS Banner
Back
Volume Conversions

Author: Guitarman 05/08/2021
Language: Visual Basic .NET
Tags:


Description:

Functions to convert volumes

Article:

Public Enum Volume As Integer
        CubicFeet = 1
        CubicMeters = 2
        CubicYards = 3
        CubicInches = 4
        CubicCentimeters = 5
    End Enum

    ''' <summary>
    ''' Volume Conversion EX: Cubic Feet to Cubic Meters and Cubic Meters to Cubic Feet
    ''' </summary>
    ''' <param name="Value"></param>
    ''' <param name="ConvertFrom"></param>
    ''' <param name="ConvertTo"></param>
    ''' <returns>Double</returns>
    ''' <remarks></remarks>
    Public Shared Function VolumeConversion(ByVal Value As Double, ByVal ConvertFrom As Volume, ByVal ConvertTo As Volume) As Double
        Dim ReturnValue As Double = 0


        'Cubic Feet to Cubic Meters
        If ConvertFrom = Volume.CubicMeters And ConvertTo = Volume.CubicYards Then

            ReturnValue = Round((Value * 1.30488), 14)

        End If

        'Cubic Meters to Cubic Inches
        If ConvertFrom = Volume.CubicMeters And ConvertTo = Volume.CubicInches Then

            ReturnValue = Round((Value * 60975.60976), 14)

        End If

        'Cubic Meters to Cubic Centimeters
        If ConvertFrom = Volume.CubicMeters And ConvertTo = Volume.CubicCentimeters Then

            ReturnValue = Round((Value * 999210.97561), 14)

        End If

        'Cubic Meters to Cubic Feet
        If ConvertFrom = Volume.CubicMeters And ConvertTo = Volume.CubicFeet Then

            ReturnValue = Round((Value * 35.28683), 14)

        End If

        'Cubic Yards to Cubic Meters
        If ConvertFrom = Volume.CubicYards And ConvertTo = Volume.CubicMeters Then

            ReturnValue = Round((Value * 0.76636), 14)

        End If

        'Cubic Yards to Cubic Inches
        If ConvertFrom = Volume.CubicYards And ConvertTo = Volume.CubicInches Then

            ReturnValue = Round((Value * 46728.97196), 14)

        End If

        'Cubic Yards to Cubic Centimeters
        If ConvertFrom = Volume.CubicYards And ConvertTo = Volume.CubicCentimeters Then

            ReturnValue = Round((Value * 765750.46729), 14)

        End If

        'Cubic Yards to Cubic Feet
        If ConvertFrom = Volume.CubicYards And ConvertTo = Volume.CubicFeet Then

            ReturnValue = Round((Value * 27.04224), 14)

        End If

        'Cubic inches to Cubic Meters
        If ConvertFrom = Volume.CubicInches And ConvertTo = Volume.CubicMeters Then

            ReturnValue = Round((Value * 0.000016387), 14)

        End If

        'Cubic inches to Cubic Yards
        If ConvertFrom = Volume.CubicInches And ConvertTo = Volume.CubicYards Then

            ReturnValue = Round((Value * 0.0000214334108513), 14)

        End If

        'Cubic inches to Cubic Centimeters
        If ConvertFrom = Volume.CubicInches And ConvertTo = Volume.CubicCentimeters Then

            ReturnValue = Round((Value * 16.38706), 14)

        End If

        'Cubic inches to Cubic Feet
        If ConvertFrom = Volume.CubicInches And ConvertTo = Volume.CubicFeet Then

            ReturnValue = Round((Value * 0.00058), 14)

        End If

        'Cubic centimeters to Cubic Meters
        If ConvertFrom = Volume.CubicCentimeters And ConvertTo = Volume.CubicMeters Then

            ReturnValue = Round((Value * 0.000001), 14)

        End If

        'Cubic centimeters to Cubic Yards
        If ConvertFrom = Volume.CubicCentimeters And ConvertTo = Volume.CubicYards Then

            ReturnValue = Round((Value * 0.000001308), 14)

        End If

        'Cubic centimeters to Cubic Centimeters
        If ConvertFrom = Volume.CubicCentimeters And ConvertTo = Volume.CubicInches Then

            ReturnValue = Round((Value * 0.06102), 14)

        End If

        'Cubic centimeters to Cubic Feet
        If ConvertFrom = Volume.CubicCentimeters And ConvertTo = Volume.CubicFeet Then

            ReturnValue = Round((Value * 0.0000353147248277), 14)

        End If

        'Cubic feet to Cubic Meters
        If ConvertFrom = Volume.CubicFeet And ConvertTo = Volume.CubicMeters Then

            ReturnValue = Round((Value * 0.02834), 14)

        End If

        'Cubic feet to Cubic Yards
        If ConvertFrom = Volume.CubicFeet And ConvertTo = Volume.CubicYards Then

            ReturnValue = Round((Value * 0.03698), 14)

        End If

        'Cubic feet to Cubic Centimeters
        If ConvertFrom = Volume.CubicFeet And ConvertTo = Volume.CubicInches Then

            ReturnValue = Round((Value * 1727.99912), 14)

        End If

        'Cubic feet to Cubic Feet
        If ConvertFrom = Volume.CubicFeet And ConvertTo = Volume.CubicCentimeters Then

            ReturnValue = Round((Value * 28316.82518), 14)

        End If

        Return ReturnValue
    End Function



Back
Comments
Add Comment
There are no comments yet.