Access routine for converting fractional to decimal newbie help?

  • Thread starter Thread starter gdnmt
  • Start date Start date
G

gdnmt

Guest
Hi. I'm new here and a wannabe Access guy. The implementation and customization I would like to implement between AutoCAD and Access knows no boundaries and to date I have been relying on someone who knows Access beginner-intermediate level who pretty much dogged my project out, so I have to pick up the pieces and learn how to do it myself :(.

Between all the Computer stuff I am involved in taking my first steps in Access is intimidating to say the least!

I developed a bill of materials program in AutoCAD that works with weights and lengths for steel materials in feet and inches. I then can extract the info to delimited text file and from there I want to take it to a database for generating ordering and work orders. I don't know much about Access but I can get my data there and run through wizards to get what I want to the point of where I need to start generating forms by manipulating some numbers but they exist as text.values in Access ex “13’3-1/2” so I can’t manipulate them without converting them to decimal.

The problem is though, when dealing with the steel members for ordering material, I need to deal with them in fractional form ex. 19'11-13/16", 0'0-3/8" etc, so I have to convert them back anfd forth between decimal and inches in Access to do some adding and multiplication and for my order sheets for the suppliers and workers. I haven’t been able to find any programs or routines for this conversion process. Does anyone have any pointers or seen any code somewhere that might help me come up with a conversion routine? I set up the AutoCAD program to output in a standard formula where the ‘character and – character will be my separators for the conversion process. I don’t know VB :( but I can cut and paste with the best of them ;)

Thanks for taking the time to read this and any help you might lend an Access newbie like myself *humble sigh * I really hope someone here has seen this dilemma before or knows of a site or two I can scour for help. My apologies if I missed a post somewhere here discussing this conversion, but my search didn’t shown anything other than some metric conversion routines, which is pretty close...thanks.
 
Give this a try. You will have to modify for your purpose ...
Code:
Public Sub Frac_Conv(ByRef Numer, Denom As Long, ByVal DecVal As Double)

    Denom = 10 ^ (Len(CStr(DecVal)) - 2)
    Numer = DecVal * 10 ^ (Len(CStr(DecVal)) - 2)
    
    
    Do While Numer Mod 5 = 0
        Numer = Numer \ 5
        Denom = Denom \ 5
    Loop

    Do While Numer Mod 2 = 0
        Numer = Numer \ 2
        Denom = Denom \ 2
    Loop

End Sub

Public Sub testfrac()
Dim top, bottom As Long
Dim MyDec As Double

    top = 0
    bottom = 0
    MyDec = 0.0125
    Call Frac_Conv(top, bottom, MyDec)
    MsgBox MyDec & " ---> " & top & "/" & bottom
    
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom