Results 1 to 6 of 6

Thread: [RESOLVED] Built in function for Roman Numerals?

  1. #1

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Resolved [RESOLVED] Built in function for Roman Numerals?

    Hey all,

    I'm making a notetaking program for a computer's class, and I was wondering if there was any built in VB function to retreive roman numerals such as I, II, III, ect.

    What I have done is made a long that had roman numberals up to 50 like this..

    lngData = "I|II|III|IV|V|VI|VII|VIII"

    and then split the long where the |'s are and just called the array that the long was split into. But if there was a function to get roman numerals already that would be much easier

    thanks

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Built in function for Roman Numerals?

    Hi paralinx,

    This tread any goood?

    http://www.vbforums.com/showthread.p...ighlight=roman

  3. #3

  4. #4
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: Built in function for Roman Numerals?

    This only converts value less than 1,000:
    VB Code:
    1. 'NOTE:  49 is converted as XLIV, instead of the shortcut IL.
    2. '       95 is converted as XCV, instead of the shortcut VC.
    3. Private Function RomanNumerals(ByVal Value As Long) As String
    4.   Dim Ones     As Long
    5.   Dim Tens     As Long
    6.   Dim Hundreds As Long
    7.  
    8.   If Value < 1 Then
    9.     RomanNumerals = "Value too small."
    10.     Exit Function
    11.   End If
    12.  
    13.   Ones = Value Mod 10
    14.   Tens = (Value \ 10) Mod 10
    15.   Hundreds = Value \ 100
    16.  
    17.   If Hundreds > 9 Then
    18.     RomanNumerals = "Value too large."
    19.   Else
    20.     RomanNumerals = ConvertPlace(Hundreds, "C", "D", "M") _
    21.                   & ConvertPlace(Tens, "X", "L", "C") _
    22.                   & ConvertPlace(Ones, "I", "V", "X")
    23.   End If
    24. End Function
    25.  
    26. Private Function ConvertPlace(ByVal Value As Long, _
    27.                               ByVal One As String, _
    28.                               ByVal Five As String, _
    29.                               ByVal Ten As String) As String
    30.   Debug.Assert Value >= 0
    31.   Debug.Assert Value <= 10
    32.  
    33.   Select Case Value
    34.   Case Is < 0:   ConvertPlace = "** ERROR **"
    35.   Case Is = 0:   ConvertPlace = ""
    36.   Case Is < 4:   ConvertPlace = String$(Value, One)
    37.   Case Is < 6:   ConvertPlace = String$(5 - Value, One) & Five
    38.   Case Is < 9:   ConvertPlace = Five & String$(Value - 5, One)
    39.   Case Is <= 10: ConvertPlace = String$(10 - Value, One) & Ten
    40.   Case Else:     ConvertPlace = "** ERROR **"
    41.   End Select
    42. End Function

  5. #5
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Built in function for Roman Numerals?

    Here's a function that will give you all Roman numerals upto 3,999.
    VB Code:
    1. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    2. ' Comments:     This function returns a string that is the Roman
    3. '               Numeral version of a passed Arabic number.
    4. '               The function will only work if the value is less
    5. '               than 4000
    6. '
    7. ' Arguments:    Arabic      The arabic number to be converted to
    8. '                           Roman
    9. '
    10. ' Date          Developer       Action
    11. ' --------------------------------------------------------------
    12. ' 03/14/06      Declan Kenny    Initial version
    13. '
    14. Function GetRoman(Arabic As Long) As String
    15. Dim sArabic As String
    16. Dim sReturn As String
    17.    
    18.     If Arabic > 3999 Then
    19.         GetRoman = "Value is too large"
    20.         Exit Function
    21.     End If
    22.    
    23.     sArabic = CStr(Arabic)
    24.    
    25.     'Thousand Part
    26.     If Len(sArabic) = 4 Then
    27.         sReturn = String(CLng(Left(sArabic, 1)), "M")
    28.         sArabic = Right(sArabic, 3)
    29.     End If
    30.    
    31.     'Hundred Part
    32.     If Len(sArabic) = 3 Then
    33.         Select Case CLng(Left(sArabic, 1))
    34.             Case 1 To 3
    35.                 sReturn = sReturn & String(CLng(Left(sArabic, 1)), "C")
    36.             Case 4
    37.                 sReturn = sReturn & "CD"
    38.             Case 5
    39.                 sReturn = sReturn & "D"
    40.             Case 6 To 8
    41.                 sReturn = sReturn & "D" & String(CLng(Left(sArabic, 1)) - 5, "C")
    42.             Case 9
    43.                 sReturn = sReturn & "CM"
    44.         End Select
    45.         sArabic = Right(sArabic, 2)
    46.     End If
    47.    
    48.     'Ten Part
    49.     If Len(sArabic) = 2 Then
    50.         Select Case CLng(Left(sArabic, 1))
    51.             Case 1 To 3
    52.                 sReturn = sReturn & String(CLng(Left(sArabic, 1)), "X")
    53.             Case 4
    54.                 sReturn = sReturn & "XL"
    55.             Case 5
    56.                 sReturn = sReturn & "L"
    57.             Case 6 To 8
    58.                 sReturn = sReturn & "L" & String(CLng(Left(sArabic, 1)) - 5, "X")
    59.             Case 9
    60.                 sReturn = sReturn & "XC"
    61.         End Select
    62.         sArabic = Right(sArabic, 1)
    63.     End If
    64.    
    65.     'One Part
    66.     Select Case CLng(Left(sArabic, 1))
    67.         Case 1 To 3
    68.             sReturn = sReturn & String(CLng(Left(sArabic, 1)), "I")
    69.         Case 4
    70.             sReturn = sReturn & "IV"
    71.         Case 5
    72.             sReturn = sReturn & "V"
    73.         Case 6 To 8
    74.             sReturn = sReturn & "V" & String(CLng(Left(sArabic, 1)) - 5, "I")
    75.         Case 9
    76.             sReturn = sReturn & "IX"
    77.     End Select
    78.    
    79.     GetRoman = sReturn
    80. End Function
    Last edited by DKenny; Mar 14th, 2006 at 05:27 PM.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  6. #6

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Built in function for Roman Numerals?

    Great thanks,

    I would have never figured it out

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