HS Banner
Back
Length Conversions

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


Description:

Functions to convert length

Article:

Public Enum Length As Integer
        Centimeters = 1
        Meters = 2
        Feet = 3
        Kilometers = 4
        Miles = 5
        Inches = 6
        Yards = 7
    End Enum

    ''' <summary>
    ''' Length Conversions
    ''' </summary>
    ''' <param name="Value"></param>
    ''' <param name="ConvertFrom"></param>
    ''' <param name="ConvertTo"></param>
    ''' <returns>Double</returns>
    ''' <remarks></remarks>
    Public Shared Function LengthConversion(ByVal Value As Double, ByVal ConvertFrom As Length, ByVal ConvertTo As Length) As Double
        Dim ReturnValue As Double = 0


        'Centimeters to Meters
        If ConvertFrom = Length.Centimeters And ConvertTo = Length.Meters Then

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

        End If

        'Centimeters to feet
        If ConvertFrom = Length.Centimeters And ConvertTo = Length.Feet Then

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

        End If

        'Centimeters to yards
        If ConvertFrom = Length.Centimeters And ConvertTo = Length.Yards Then

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

        End If

        'Centimeters to kilometers
        If ConvertFrom = Length.Centimeters And ConvertTo = Length.Kilometers Then

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

        End If

        'Centimeters to miles
        If ConvertFrom = Length.Centimeters And ConvertTo = Length.Miles Then

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

        End If

        'Centimeters to inches
        If ConvertFrom = Length.Centimeters And ConvertTo = Length.Inches Then

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

        End If

        'meters to Meters
        If ConvertFrom = Length.Meters And ConvertTo = Length.Centimeters Then

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

        End If

        'meters to feet
        If ConvertFrom = Length.Meters And ConvertTo = Length.Feet Then

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

        End If

        'meters to yards
        If ConvertFrom = Length.Meters And ConvertTo = Length.Yards Then

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

        End If

        'meters to kilometers
        If ConvertFrom = Length.Meters And ConvertTo = Length.Kilometers Then

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

        End If

        'meters to miles
        If ConvertFrom = Length.Meters And ConvertTo = Length.Miles Then

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

        End If

        'meters to inches
        If ConvertFrom = Length.Meters And ConvertTo = Length.Inches Then

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

        End If

        'Feet to Centimeters
        If ConvertFrom = Length.Feet And ConvertTo = Length.Centimeters Then

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

        End If

        'Feet to Meters
        If ConvertFrom = Length.Feet And ConvertTo = Length.Meters Then

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

        End If

        'Feet to yards
        If ConvertFrom = Length.Feet And ConvertTo = Length.Yards Then

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

        End If

        'Feet to kilometers
        If ConvertFrom = Length.Feet And ConvertTo = Length.Kilometers Then

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

        End If

        'Feet to miles
        If ConvertFrom = Length.Feet And ConvertTo = Length.Miles Then

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

        End If

        'Feet to inches
        If ConvertFrom = Length.Feet And ConvertTo = Length.Inches Then

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

        End If

        'Yards to Centimeters
        If ConvertFrom = Length.Yards And ConvertTo = Length.Centimeters Then

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

        End If

        'Yards to Meters
        If ConvertFrom = Length.Yards And ConvertTo = Length.Meters Then

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

        End If

        'Yards to feet
        If ConvertFrom = Length.Yards And ConvertTo = Length.Feet Then

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

        End If

        'Yards to kilometers
        If ConvertFrom = Length.Yards And ConvertTo = Length.Kilometers Then

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

        End If

        'Yards to miles
        If ConvertFrom = Length.Yards And ConvertTo = Length.Miles Then

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

        End If

        'Yards to inches
        If ConvertFrom = Length.Yards And ConvertTo = Length.Inches Then

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

        End If

        'Kilometers to Centimeters
        If ConvertFrom = Length.Kilometers And ConvertTo = Length.Centimeters Then

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

        End If

        'Kilometers to Meters
        If ConvertFrom = Length.Kilometers And ConvertTo = Length.Meters Then

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

        End If

        'Kilometers to feet
        If ConvertFrom = Length.Kilometers And ConvertTo = Length.Feet Then

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

        End If

        'Kilometers to Yards
        If ConvertFrom = Length.Kilometers And ConvertTo = Length.Yards Then

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

        End If

        'Kilometers to miles
        If ConvertFrom = Length.Kilometers And ConvertTo = Length.Miles Then

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

        End If

        'Kilometers to inches
        If ConvertFrom = Length.Kilometers And ConvertTo = Length.Inches Then

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

        End If

        'Miles to Centimeters
        If ConvertFrom = Length.Miles And ConvertTo = Length.Centimeters Then

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

        End If

        'Miles to Meters
        If ConvertFrom = Length.Miles And ConvertTo = Length.Meters Then

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

        End If

        'Miles to feet
        If ConvertFrom = Length.Miles And ConvertTo = Length.Feet Then

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

        End If

        'Miles to Yards
        If ConvertFrom = Length.Miles And ConvertTo = Length.Yards Then

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

        End If

        'Miles to Kilometers
        If ConvertFrom = Length.Miles And ConvertTo = Length.Kilometers Then

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

        End If

        'Miles to inches
        If ConvertFrom = Length.Miles And ConvertTo = Length.Inches Then

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

        End If

        'Inches to Centimeters
        If ConvertFrom = Length.Inches And ConvertTo = Length.Centimeters Then

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

        End If

        'Inches to Meters
        If ConvertFrom = Length.Inches And ConvertTo = Length.Meters Then

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

        End If

        'Inches to feet
        If ConvertFrom = Length.Inches And ConvertTo = Length.Feet Then

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

        End If

        'Inches to Yards
        If ConvertFrom = Length.Inches And ConvertTo = Length.Yards Then

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

        End If

        'Inches to Kilometers
        If ConvertFrom = Length.Inches And ConvertTo = Length.Kilometers Then

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

        End If

        'Inches to Miles
        If ConvertFrom = Length.Inches And ConvertTo = Length.Miles Then

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

        End If

        Return ReturnValue
    End Function


Back
Comments
Add Comment
There are no comments yet.