G
Guest
I have a form with two text boxes, one called txtDecimal, and another called
txtLength. I want to enter a decimal value into txtDecimal, and output a feet
and inches value into txtLength. Here is code used preveously in excel for
this.
Public Function lentext(Feetin As Double)
' This function will change a decimal number of feet to the text string
' representation of feet, inches, and fractional inches.
' It will round the fractional inches to the nearest 1/x where x is the
denominator.
Denominator = 8 ' must be 2, 4, 8, 16, 32, 64, 128, etc.
NbrFeet = Int(Feetin)
InchIn = (Feetin - NbrFeet) * 12
NbrInches = Int(InchIn)
FracIn = (InchIn - NbrInches) * Denominator
Numerator = Application.WorksheetFunction.Round(FracIn, 0)
If Numerator = 0 Then
FracText = ""
ElseIf Numerator = Denominator Then
NbrInches = NbrInches + 1
FracText = ""
Else
Do
' If the numerator is even, divide both numerator and divisor by 2
If Numerator = Application.WorksheetFunction.Even(Numerator) Then
Numerator = Numerator / 2
Denominator = Denominator / 2
Else
FracText = " " & Numerator & "/" & Denominator
Exit Do
End If
Loop
End If
lentext = NbrFeet & "' " & NbrInches & FracText & """"
End Function
txtLength. I want to enter a decimal value into txtDecimal, and output a feet
and inches value into txtLength. Here is code used preveously in excel for
this.
Public Function lentext(Feetin As Double)
' This function will change a decimal number of feet to the text string
' representation of feet, inches, and fractional inches.
' It will round the fractional inches to the nearest 1/x where x is the
denominator.
Denominator = 8 ' must be 2, 4, 8, 16, 32, 64, 128, etc.
NbrFeet = Int(Feetin)
InchIn = (Feetin - NbrFeet) * 12
NbrInches = Int(InchIn)
FracIn = (InchIn - NbrInches) * Denominator
Numerator = Application.WorksheetFunction.Round(FracIn, 0)
If Numerator = 0 Then
FracText = ""
ElseIf Numerator = Denominator Then
NbrInches = NbrInches + 1
FracText = ""
Else
Do
' If the numerator is even, divide both numerator and divisor by 2
If Numerator = Application.WorksheetFunction.Even(Numerator) Then
Numerator = Numerator / 2
Denominator = Denominator / 2
Else
FracText = " " & Numerator & "/" & Denominator
Exit Do
End If
Loop
End If
lentext = NbrFeet & "' " & NbrInches & FracText & """"
End Function