Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting inches to feet and inches

Status
Not open for further replies.

patioman

Technical User
Dec 18, 2002
1
0
0
US
I'm trying to calculate a field that represents length in inches and change it to three fields that will display whole feet then inches, then a decimal equivalent of the fraction of the inch.
an example is 147.5". the first field would show 14. the next one would show 3.and the last one would show.5. I'm able to get 14.47777 or something like that and I can't get any further help around here
 
Hi!

Try this:

Assume FirstTextBox has the total inches

txtFeet = Int(FirstTextBox / 12)
txtInches = Int(FirstTextBox - txtFeet * 12)
txtFraction = FirstTextBox - txtFeet * 12 - txtInches

hth
Jeff Bridgham
bridgham@purdue.edu
 
Code:
Public Function basInch2FtIn(InchIn As Single) As Variant()

    Dim MyFt As Integer
    Dim MyIn As Single
    Dim MyFractIn As Single
    Dim MyVar(2) As Variant

    MyFt = InchIn / 12
    MyIn = InchIn - (12 * MyFt)
    MyFractIn = MyIn - Int(MyIn)

    MyVar(0) = MyFt
    MyVar(1) = MyIn
    MyVar(2) = MyFractIn

    'To Return a SINGLE string formatted as feet and Inches (w/ decimal fractions _
     of the inches, use this return and change hte return Type to String

    'Example Usage for THIS return:
    '? basInch2FtIn(147.5)
    '12Ft, 3.5In

'    basInch2FtIn = Trim(Str(MyFt) & "Ft") & ", " & Trim(Str(Int(MyIn) + MyFractIn) & "In")

    'To Return the elements of the conversion in an array, use this return _
     with the return type as a variant Array (e.g. "As Variant()")
    basInch2FtIn = MyVar


End Function
Public Function basTestFtIn(In2Test As Single)

    'Michael Red    12/18/2002
    'To ILLUSTRATE the conversion of Feet to Inches as an array of Feet, Inches and _
     and fractions of an inch

    '? basTestFtIn(147.5)
    '12
    '3.5
    '0.5


    Dim MyAry() As Variant
    Dim Idx As Integer

    MyAry = basInch2FtIn(In2Test)

    Idx = 0
    While Idx <= UBound(MyAry)
        Debug.Print MyAry(Idx)
        Idx = Idx + 1
    Wend
End Function
[code]
 MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Code:
Public Function basInch2FtIn(InchIn As Single) As Variant()

    Dim MyFt As Integer
    Dim MyIn As Single
    Dim MyFractIn As Single
    Dim MyVar(2) As Variant

    MyFt = InchIn / 12
    MyIn = InchIn - (12 * MyFt)
    MyFractIn = MyIn - Int(MyIn)

    MyVar(0) = MyFt
    MyVar(1) = MyIn
    MyVar(2) = MyFractIn

    'To Return a SINGLE string formatted as feet and Inches (w/ decimal fractions _
     of the inches, use this return and change hte return Type to String

    'Example Usage for THIS return:
    '? basInch2FtIn(147.5)
    '12Ft, 3.5In

'    basInch2FtIn = Trim(Str(MyFt) & &quot;Ft&quot;) & &quot;, &quot; & Trim(Str(Int(MyIn) + MyFractIn) & &quot;In&quot;)

    'To Return the elements of the conversion in an array, use this return _
     with the return type as a variant Array (e.g. &quot;As Variant()&quot;)
    basInch2FtIn = MyVar


End Function
Public Function basTestFtIn(In2Test As Single)

    'Michael Red    12/18/2002
    'To ILLUSTRATE the conversion of Feet to Inches as an array of Feet, Inches and _
     and fractions of an inch

    '? basTestFtIn(147.5)
    '12
    '3.5
    '0.5


    Dim MyAry() As Variant
    Dim Idx As Integer

    MyAry = basInch2FtIn(In2Test)

    Idx = 0
    While Idx <= UBound(MyAry)
        Debug.Print MyAry(Idx)
        Idx = Idx + 1
    Wend
End Function
[code]
 MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Another variation.

Dim fraction As Double, hours As Integer, total As Double, minuts As Integer
total = 147.5
fraction = total - Int(total)
hours = Int(total) / 12
minuts = Int(total) Mod 12
Debug.Print fraction
Debug.Print hours
Debug.Print minuts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top