MetricToUSStandard

Converts a Metric Measure into a US Standard Measure.
Arguments:
metricmeasure > Metric measure to convert into a US Standard measurement (This must be a number only)
conversion  > Table below for values:
 cm-in  > centimeters to inches
 cm-ft  > centimeters to feet
 m-in  > meters to inches
 m-yd  > meters to yards
 km-mi  > kilometers to miles
 g-oz  > ounces to grams
 g-lbs  > grams to pounds
 kg-oz  > kilograms to ounces
 kg-lbs > kilograms to pounds
 l-pt  > liters to pint
 l-qt  > liters to quarts
 l-gal  > liters to gallons
extensiontype > integer that specifies the type of extension to append to the converted value:
 0 > no extension (answer will be a number only)
 1 > append the standard abbreviation (lbs for pounds, in for inches, etc...)
 2 > append the word (pounds, inches, etc...)

Function MetricToUSStandard(byVal MetricMeasure, byVal Conversion, byVal ExtensionType)
 Dim tmp, multiplier, extension, ext
 Select Case UCase( Conversion )
  Case "CM-IN" : multiplier = 0.3937  : extension = "inches"  : ext = "in"
  Case "CM-FT" : multiplier = 0.0328  : extension = "feet"  : ext = "ft"
  Case "M-IN"  : multiplier = 39.37  : extension = "inches"  : ext = "in"
  Case "M-YD"  : multiplier = 1.093  : extension = "yards"  : ext = "yd"
  Case "KM-MI" : multiplier = 0.6210  : extension = "miles"  : ext = "mi"
  Case "G-OZ"  : multiplier = 0.0350  : extension = "ounces"  : ext = "oz"
  Case "G-LBS" : multiplier = 0.0020  : extension = "pounds"  : ext = "lbs"
  Case "KG-OZ" : multiplier = 35.274  : extension = "ounces"  : ext = "oz"
  Case "KG-LBS" : multiplier = 2.205  : extension = "pounds"  : ext = "lbs"
  Case "L-PT"  : multiplier = 2.113  : extension = "pints"  : ext = "pt"
  Case "L-QT"  : multiplier = 1.057  : extension = "quarts"  : ext = "qt"
  Case "L-GAL" : multiplier = 0.264  : extension = "gallons" : ext = "gal"
 End Select
 tmp = Formatnumber(multiplier * MetricMeasure, 2)
 Select Case CInt(ExtensionType)
  Case 0  : tmp = Trim( tmp )
  Case 1  : tmp = tmp & " " & ext
  Case 2  : tmp = tmp & " " & extension
  Case Else : tmp = Trim( tmp )
 End Select
 MetricToUSStandard= tmp
End Function

MetricMeasure, Conversion, ExtensionType

Views 1022 Downloads 331

'Convert', 'units', 'replace', 'change', 'calculate', 'standard', 'metric', 'us', 'grams', 'kilograms', 'liters', 'centimeters', 'meters', 'kilometers', 'NotMyWork', 'USStandardToMetric'

ANmarAmdeen
333
Math Classic ASP
Revisions

v1.0