StandardToMetric Function:
Translates a US Standard measure into a Metric measure.
Description:
The StandardToMetric function converts a US standard Measure into a Metric Measure. There are three required arguments: standardmeasure, conversion and extensiontype.
Syntax:
string = StandardToMetric(standardmeasure, conversion, extensiontype)
Details:
arguments: ============ Standardmeasure: the US Standard measure to convert (This must be a number only)
Conversion: use the table below for values:
conversion argument converts: -------------------------------------------------------------------------- in-cm - inches to centimeters
ft-cm - feet to centimeters
in-m - inches to meters
yd-m - yards to meters
mi-km - miles to kilometers
oz-g - ounces to grams
lbs-g - pounds to grams
oz-kg - ounces to kilogram
lbs-kg - pounds to kilograms pt-l - pints to liters
qt-l - quarts to liters
gal-l - gallons to liters
Extensiontype: integer that specifies the type of extension to append to the converted value:
Extensiontype argument (integer) extension -------------------------------------------------------------------------- 0 - no extension (answer will be a number only)
1 - append the standard abbreviation (g for grams, kg for kilograms, etc...)
2 - append the word (grams, kilograms)
Example:
<%
'--- translate 1oz to grams - no extension response.write StandardToMetric(1, "oz-g", 0) & "<BR>" '--- returns 28.35
'--- translate 1 mile to kilometers - abbreviated extension response.write StandardToMetric(1, "mi-km", 1) & "<BR>" '--- returns 1.61 km
'--- translate 1 foot to centimeters - full extension response.write StandardToMetric(1, "ft-cm", 2) & "<BR>" '--- returns 30.48 centimeters
%>
ASP Source Code:
<%
Private Function StandardToMetric(byVal StandardMeasure, _ byVal Conversion, byVal ExtensionType) Dim tmp, multiplier, extension, ext Select Case UCase( Conversion ) Case "IN-CM" : multiplier = 2.54 : _ extension = "centimeters" : ext = "cm" Case "FT-CM" : multiplier = 30.48 : _ extension = "centimeters" : ext = "cm" Case "IN-M" : multiplier = 0.00254 : _ extension = "meters" : ext = "m" Case "YD-M" : multiplier = 0.914 : _ extension = "meters" : ext = "m" Case "MI-KM" : multiplier = 1.609 : _ extension = "kilometers" : ext = "km" Case "OZ-G" : multiplier = 28.35 : _ extension = "grams" : ext = "g" Case "LBS-G" : multiplier = 453.59 : _ extension = "grams" : ext = "g" Case "OZ-KG" : multiplier = 0.028 : _ extension = "kilograms" : ext = "kg" Case "LBS-KG" : multiplier = 0.454 : _ extension = "kilograms" : ext = "kg" Case "PT-L" : multiplier = 0.473 : _ extension = "liters" : ext = "L" Case "QT-L" : multiplier = 0.946 : _ extension = "liters" : ext = "L" Case "GAL-L" : multiplier = 3.785 : _ extension = "liters" : ext = "L" End Select tmp = Formatnumber(multiplier * StandardMeasure, 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 StandardToMetric = tmp End Function
%>
|