Results 1 to 3 of 3

Thread: Number conversions

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Arlington, Washington USA
    Posts
    1

    Post

    I know that you can add an OLE to your program in VB6 linked to Excel to do a decimal to fraction conversion, but I would like to complete my program to run independent to MS Office applications.
    I know that there should be some code that will convert a decimal input to a fractional resultant but I haven't been able to figure it out. Could one of you give some insight to how the code structure should look like.
    I would really appreciate the assistance! (So would my customer!)

  2. #2
    New Member
    Join Date
    Jan 1999
    Posts
    7

    Post

    This should get you started. It will convert any fraction to its lowest common denominator(not just decimal ones).
    Private Sub Convert_to_Fraction()
    Dim Numerator As Integer
    Dim Denominator As Integer
    Dim WholeNumber As Integer
    Dim NoDivision As Boolean
    Dim Divisor As Integer
    On Error GoTo CancelErr
    Numerator = InputBox("Please enter the numerator")
    Denominator = InputBox("Please enter the denominator")
    If Numerator >= Denominator Then
    WholeNumber = Numerator / Denominator
    Numerator = Numerator Mod Denominator
    End If
    Do Until NoDivision Or Numerator = 1 Or Numerator = 0
    NoDivision = True
    For Divisor = 2 To 9
    If Numerator Mod Divisor = 0 And _
    Denominator Mod Divisor = 0 Then
    Numerator = Numerator / Divisor
    Denominator = Denominator / Divisor
    NoDivision = False
    Exit For
    End If
    Next
    Loop
    If WholeNumber > 0 Then
    If Numerator > 0 Then
    MsgBox "The final number is " & WholeNumber & "and " & _
    Numerator & "/" & Denominator
    Else
    MsgBox "The final number is " & WholeNumber
    End If
    Else
    If Numerator > 0 Then
    MsgBox "The final fraction is " & Numerator & "/" & Denominator
    Else
    MsgBox "The final number is 0"
    End If
    End If
    Exit Sub
    CancelErr:
    End Sub

  3. #3
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226

    Post

    Hi I_Compute.

    If you are looking for 1/4, 1/2 and 3/4 ONLY , then
    there is a simple way to do it in VB.

    for: 1/4 Use char(188) => ¼
    for: 1/2 Use char(189) => ½
    for: 3/4 Use char(190) => ¾

    Good Luck.

    Lyla.

    [This message has been edited by Lyla (edited 01-12-2000).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width