Unit conversion

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know how to, or where I can get, code to have a button to allow
the user to convert between metric/standard/and fractions.

Thanks
 
hagen31 said:
Does anyone know how to, or where I can get, code to have a button to allow
the user to convert between metric/standard/and fractions.


Converting from metric to "standard" is just a matter of
multiplying by the conversion factor for the units being
used. Fractions can be another issue altogether.

How are the units specified and what units are to be
converted?
 
The user need to be able to type in standard units in feet and inches, and
convert to metric meters and/or mm. Or type in meters and mm and convert to
feet and/or inches
 
OK, but I still need to know how can anyone tell what units
they typed. Are there check bxes or a combo box they use to
specify feet, inches, etc, or do we have to parse out that
information from things like 12' 8", 12 2/3', 3.8m, 380cm or
what???
 
Ok sorry misunderstood. We have to parse out the information from things like
12' 8", 12 2/3', 3.8m, 380cm. Unless specifying with check boxes or combo
boxes would be easier, I am open to both ideas. This function is really only
going to be needed in the beginning of the migration from excel to access,
becuase before nothing was standard so some items were referenced in standard
units and some in metric, but now everything is going to be in standard units
out to 3 decimals. This allows them since they know it as metric to have a
handy way of converting to the new format.

Marshall Barton said:
OK, but I still need to know how can anyone tell what units
they typed. Are there check bxes or a combo box they use to
specify feet, inches, etc, or do we have to parse out that
information from things like 12' 8", 12 2/3', 3.8m, 380cm or
what???
--
Marsh
MVP [MS Access]

The user need to be able to type in standard units in feet and inches, and
convert to metric meters and/or mm. Or type in meters and mm and convert to
feet and/or inches
 
Ok, I threw together a crude conversion function that may be
good enough for limited usage. It converts everything to
inches so you can format the result in whatever units you
want by using a simple expression.

Public Function ConvertToInches(strMeas As String) _
As Currency
Dim varUnits As Variant
Dim strExpr As String
Dim k As Integer
strExpr = strMeas

varUnits = Array(" feet", "ft", " foot", " ft", _
" inches", "", " inch", "", " in", "", _
"feet", "ft", "foot", "ft", "'", "ft", _
"inches", "", "inch", "", "in", "", """", "", _
" mm", "*.03937", " cm", "*.3937", _
" m", "*39.37", "mm", "*.03937", _
"cm", "*.3937", "m", "*39.37")
For k = 0 To UBound(varUnits) Step 2
strExpr = Replace(strExpr, varUnits(k), varUnits(k+1))
Next k

If strExpr Like "*ft*" Then 'needed to handle 12 1/2ft
strExpr = "(" & Replace(strExpr, "ft", ")*12")
End If

strExpr = Replace(strExpr, " ", "+")

ConvertToInches = Eval(strExpr)
End Function

If you need something more sophisticated, try searching the
web.
 
Thanks for the help, but I think I will go back to searching the web. This
didn't seem to work but I really appreciate the help.

Marshall Barton said:
Ok, I threw together a crude conversion function that may be
good enough for limited usage. It converts everything to
inches so you can format the result in whatever units you
want by using a simple expression.

Public Function ConvertToInches(strMeas As String) _
As Currency
Dim varUnits As Variant
Dim strExpr As String
Dim k As Integer
strExpr = strMeas

varUnits = Array(" feet", "ft", " foot", " ft", _
" inches", "", " inch", "", " in", "", _
"feet", "ft", "foot", "ft", "'", "ft", _
"inches", "", "inch", "", "in", "", """", "", _
" mm", "*.03937", " cm", "*.3937", _
" m", "*39.37", "mm", "*.03937", _
"cm", "*.3937", "m", "*39.37")
For k = 0 To UBound(varUnits) Step 2
strExpr = Replace(strExpr, varUnits(k), varUnits(k+1))
Next k

If strExpr Like "*ft*" Then 'needed to handle 12 1/2ft
strExpr = "(" & Replace(strExpr, "ft", ")*12")
End If

strExpr = Replace(strExpr, " ", "+")

ConvertToInches = Eval(strExpr)
End Function

If you need something more sophisticated, try searching the
web.
--
Marsh
MVP [MS Access]

We have to parse out the information from things like
12' 8", 12 2/3', 3.8m, 380cm. Unless specifying with check boxes or combo
boxes would be easier, I am open to both ideas. This function is really only
going to be needed in the beginning of the migration from excel to access,
becuase before nothing was standard so some items were referenced in standard
units and some in metric, but now everything is going to be in standard units
out to 3 decimals. This allows them since they know it as metric to have a
handy way of converting to the new format.
 
Back
Top