|
-
Jul 25th, 2001, 04:48 PM
#1
Thread Starter
Frenzied Member
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.
-
Jul 25th, 2001, 05:35 PM
#2
AFAIK, no, you'll have to write one yourself. (or find someone to do it for you)
-
Jul 25th, 2001, 06:23 PM
#3
Attached is a control that'll do the job for you.
-
Jul 25th, 2001, 06:46 PM
#4
PowerPoster
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.
-
Jul 25th, 2001, 08:10 PM
#5
Registered User
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?
-
Jul 26th, 2001, 01:00 AM
#6
Registered User
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:
Public Function NumToRN(ByVal Num As Variant) As String
' Nucleus
' Turn an integer into roman numerals
Dim Compare@, Div@, b As Boolean
Num = CCur(FormatNumber(Num, 0)) ' Round to nearest integer and convert to currency
Compare = 1000
Do While Num
Div = Num / Compare
If Div >= 1 Then
NumToRN = NumToRN & String(Int(Div), RomanNumerals(Compare))
Num = Num - Int(Div) * Compare
Else
If b And Div >= 0.8 And Div < 1 Then
NumToRN = NumToRN & RomanNumerals(0.8 * Compare)
Num = Num - 0.8 * Compare
ElseIf Not b And Div >= 0.9 And Div < 1 Then
NumToRN = NumToRN & RomanNumerals(0.9 * Compare)
Num = Num - 0.9 * Compare
End If
If Not b Then Compare = Compare / 2 Else Compare = Compare / 5
b = Not b
End If
Loop
End Function
Private Function RomanNumerals(ByVal Num As Variant) As String
Num = FormatNumber(Num, 0)
Select Case Num
Case 1
RomanNumerals = "I"
Case 4
RomanNumerals = "IV"
Case 5
RomanNumerals = "V"
Case 9
RomanNumerals = "IX"
Case 10
RomanNumerals = "X"
Case 40
RomanNumerals = "XL"
Case 50
RomanNumerals = "L"
Case 90
RomanNumerals = "XC"
Case 100
RomanNumerals = "C"
Case 400
RomanNumerals = "CD"
Case 500
RomanNumerals = "D"
Case 900
RomanNumerals = "CM"
Case 1000
RomanNumerals = "M"
End Select
End Function
Usage:
VB Code:
Private Sub Command1_Click()
MsgBox NumToRN(1999)
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.
-
Jul 26th, 2001, 11:34 AM
#7
Thread Starter
Frenzied Member
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.
-
Jul 26th, 2001, 12:17 PM
#8
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!!
-
Jul 26th, 2001, 06:42 PM
#9
Registered User
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?
-
Sep 11th, 2001, 07:40 AM
#10
Hyperactive Member
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.
-
Sep 11th, 2001, 07:51 AM
#11
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|