Results 1 to 11 of 11

Thread: Converting to Roman numerals

  1. #1

    Thread Starter
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075

    Question Converting to Roman numerals

    Is there any function in VB that converts numbers to Roman Numerals? I know there is one in Excel. Please help.

  2. #2
    Gerco
    Guest
    AFAIK, no, you'll have to write one yourself. (or find someone to do it for you)

  3. #3
    Matthew Gates
    Guest
    Attached is a control that'll do the job for you.

  4. #4
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Are u serious!! Does Excel really have that?? No wonder it is called bloatware. I am sure converting any number to Roman Numerals would be dead easy in code, even easier than converting numbers to words for cheques/checks.
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  5. #5
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    How do you count in Roman Numerals?

    I, II, III, IV, V, VI, VII, VIII, IX, X, XI, XII, XIII, XIV, XV,

    20?
    30?
    40?
    50?
    60?
    70?
    80?
    90?
    100?
    1,000?
    1,000,000?
    1,000,000,000?

  6. #6
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Ok I found a definition of roman numerals here:
    http://www.cod.edu/people/faculty/lawrence/romans00.htm

    On the basis of this try this function:

    VB Code:
    1. Public Function NumToRN(ByVal Num As Variant) As String
    2.  ' Nucleus
    3.  ' Turn an integer into roman numerals
    4.  Dim Compare@, Div@, b As Boolean
    5.  Num = CCur(FormatNumber(Num, 0)) ' Round to nearest integer and convert to currency
    6.  
    7.  Compare = 1000
    8.  
    9.  Do While Num
    10.    
    11.     Div = Num / Compare
    12.    
    13.     If Div >= 1 Then
    14.        
    15.         NumToRN = NumToRN & String(Int(Div), RomanNumerals(Compare))
    16.         Num = Num - Int(Div) * Compare
    17.        
    18.     Else
    19.    
    20.         If b And Div >= 0.8 And Div < 1 Then
    21.             NumToRN = NumToRN & RomanNumerals(0.8 * Compare)
    22.             Num = Num - 0.8 * Compare
    23.        
    24.         ElseIf Not b And Div >= 0.9 And Div < 1 Then
    25.             NumToRN = NumToRN & RomanNumerals(0.9 * Compare)
    26.             Num = Num - 0.9 * Compare
    27.            
    28.         End If
    29.        
    30.         If Not b Then Compare = Compare / 2 Else Compare = Compare / 5
    31.         b = Not b
    32.        
    33.     End If
    34.    
    35.  Loop
    36.  
    37. End Function
    38.  
    39.  
    40. Private Function RomanNumerals(ByVal Num As Variant) As String
    41.  Num = FormatNumber(Num, 0)
    42.  Select Case Num
    43.     Case 1
    44.         RomanNumerals = "I"
    45.     Case 4
    46.         RomanNumerals = "IV"
    47.     Case 5
    48.         RomanNumerals = "V"
    49.     Case 9
    50.         RomanNumerals = "IX"
    51.     Case 10
    52.         RomanNumerals = "X"
    53.     Case 40
    54.         RomanNumerals = "XL"
    55.     Case 50
    56.         RomanNumerals = "L"
    57.     Case 90
    58.         RomanNumerals = "XC"
    59.     Case 100
    60.         RomanNumerals = "C"
    61.     Case 400
    62.         RomanNumerals = "CD"
    63.     Case 500
    64.         RomanNumerals = "D"
    65.     Case 900
    66.         RomanNumerals = "CM"
    67.     Case 1000
    68.         RomanNumerals = "M"
    69.  End Select
    70. End Function

    Usage:
    VB Code:
    1. Private Sub Command1_Click()
    2.  MsgBox NumToRN(1999)
    3. End Sub

    Use with caution as has only just been thrown together. Any bug please post.

    I could if you know how to draw a line over letters like V then I can ammend the function to include the shorthand for larger numbers such as 900,000 which is CM with line over it rather than a string of 900 Ms.

    Also does the function need to handle negative numbers?
    Last edited by Nucleus; Jul 26th, 2001 at 01:59 AM.

  7. #7

    Thread Starter
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075

    Talking

    Thanks all for the replies. I ended up writing my own function that works. I was hoping to find something else, but didn't see your control Matt until I was already done. BeachBum, yes Excel really has a Roman function for converting decimal to roman numerals, it should be in VB then I would of thought, but no. Anyways thanks for the help.

  8. #8
    wossname
    Guest
    I don't know why all these historians rattle on about how clever the Romans were, oh wow they invented underwater concrete, whoopy-doo. They could do that, but a decent numerical notation was apparently above them!

    I was told by a reliable source that there are at least 3 different ways to write the number 127454 in Roman numerals (I may have remembered that num wrong though). In any other sensible number system, there is only ever 1 way to write a number!

    Ooh, Mr Glatiator, what a big gladivs you have, hey pvt that down! Arggggghhhhhh!!

  9. #9
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Originally posted by seoptimizer2001
    Thanks all for the replies. I ended up writing my own function that works. I was hoping to find something else, but didn't see your control Matt until I was already done. BeachBum, yes Excel really has a Roman function for converting decimal to roman numerals, it should be in VB then I would of thought, but no. Anyways thanks for the help.
    Can you post or send me your function seoptimizer?

    wossname,

    I was told by a reliable source that there are at least 3 different ways to write the number 127454 in Roman numerals (I may have remembered that num wrong though). In any other sensible number system, there is only ever 1 way to write a number!
    How does having multiple ways of writing a number reduce it's sensibility? Perhaps it provides more flexibility?

  10. #10
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    350
    Originally posted by Nucleus


    How does having multiple ways of writing a number reduce it's sensibility? Perhaps it provides more flexibility?
    Well I suppose in a superficial way one could say it's more flexible, but why does it need to be? My route to work is flexible, because I can make decisions based on traffic and so on: there's no earthly reason to want to write a number in more than one way. Indeed, it might make it worse, because I might write the number in one of the less obvious ways- or should I say less common- and then most people would have to puzzle over what I'm getting at and get it wrong.

    Somewhere else in this thread it was asked about negative numbers. If I remember correctly, RNs had no concept of Zero, and so it's probably unlikely that they would have -ves, I think.

    Last year my son, in 1st grade, got bored with his arithmetic homework and did a whole page of sums using RNs instead. He concluded it was quite a pain, because there's no 0 and no way that he could see, to carry.
    .

  11. #11
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Adding subtracting are difficult, multiplication and division almost impossible with RN. To me this is a bigger problem rather than having more than one way to write a number.

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