Could i have some input on doing something ... but it seems so simple and i
cant work out .. what i am doing wrong...
APART from trying to use a bit code for a function for converting mm's in to
inches and then display in a text format of xx ft - xx" - variable (sub
division of inches ie. 1/16th ,1/8th , 1/4, 10th etc which is passed a
variable)
The code for the original was found on a website.
I now need a routine that does the reverse
Take a mm's figure split in to meters, cms and mms and then display this a
text value xx m's xx . xx cms
But i wish to have the function to be able to automatically adjust from an
optional variable of showing it in
The meters cms and mm's format
The cms and mm format
And mm's format
I just cant get it in to my head.. but perhaps i should be looking a fresh
at coding rather than altering the original code.
Please find below the code of the function which takes mm and convert to the
imperial string
'\ This function converts a decimal number of inches to a text string like
5'-6 1/2"
Function CFeet(Decimal_MMs, Optional
Enter_16_32_64_Etc__To_Round_Inches_To__Fraction_Of_Inch)
'\ These variables are used to convert the decimal inches to the number
'\ of fractional units. For example 6" would convert to 96 16ths
Dim iNumUnits As Long '\ converted value = 96 in example
Dim iUnit As Double '\ unit used to convert = 1/16 in example
'\ These varibles are used to hold calculated values that will become
'\ part of the text string
Dim iFeet As Integer
Dim iInches As Integer
Dim dFraction As Double
Dim sFtSymbol As String
Application.Volatile True 'forces recalculation
'\ These variables are used to assign shorter names to input values
Dim vVal As Variant
Dim vDenominator As Variant
'\ First we assign shorter names
'\ Convertin The value passed to function in to inches
'\ Value of mm is Decimal_mm multiplied by inches value 0.0394
vVal = Decimal_MMs * 0.0394
'vval converted to a decimal_inches
vDenominator = Enter_16_32_64_Etc__To_Round_Inches_To__Fraction_Of_Inch
'\ If no denominator value was supplied, we will round to 1/9999 of inch
If IsMissing(vDenominator) Then
iUnit = 1 / 9999
Else
iUnit = 1 / vDenominator
End If
'\ Now we calculate the number of fractional units in the input value
'\ Example 6 inches = 96 16ths
iNumUnits = (vVal / iUnit)
'\ We prepare each part of text string
iFeet = Fix(iNumUnits / (12 / iUnit))
iInches = Fix((iNumUnits Mod (12 / iUnit)) * iUnit)
dFraction = (iNumUnits Mod (1 / iUnit)) * iUnit
If iFeet <> 0 Then sFtSymbol = "'-"
'\ Finally we format and return text string
CFeet = Application.Text(iFeet, "##") & sFtSymbol &
Application.Text(iInches + dFraction, "# ##/##\""")
End Function