PDA

View Full Version : Solved: convert from Roman digit to Arabic digit



Pasquale
08-25-2006, 07:01 AM
Hallo, I need Help.

1) How to convert from Roman to Arabic, convert each Roman digit into its numeric equivalent (I=1, V=5, X=10, L=50, C=100, D=500, M=1000), in a long doc?

2) after the Roman digit now there is a full stop + space, after arabic digit must be a colon without space;

Example
9 (http://javascript<b></b>:toggle('fnf_I_1-p8.2');)91 Tim. i. 9 (file:///D:/Sant'Agostino/CCEL/www.ccel.org/ccel/bible/asv.itim.1.html#iTim.1.9). says the Apostle. But it is one thing to be in the law, another under the law. Whoso is in the law, acteth according to the law; whoso is under the law, is acted upon according to the law: the one therefore is free, the other a slave. Again, the law, which is written and imposed upon the servant, is one thing; the law, which is mentally discerned by him who needeth not its “letter,” is another thing. “He will meditate by day and by night,” is to be understood either as without ceasing; or “by day” in joy, “by night” in tribulations. For it is said, “Abraham saw my day, and was glad:”10 (http://javascript<b></b>:toggle('fnf_I_1-p9.2');)10John viii. 5, 6 (file:///D:/Sant'Agostino/CCEL/www.ccel.org/ccel/bible/asv.john.8.html#John.8.5)

thanks Pasquale

mdmackillop
08-26-2006, 02:44 PM
Here's some code I adapted from an item I found on Ozgrid (no author named). I've applied it to all words preceding a full stop. Are there any Roman numerals which can be confused with words, other than "I"? The code loops at the end, but no time now to resolve that bug and I've not dealt with the colon punctuation. If the basics are OK though, let us know and the rest can be resolved.
Regards
MD


Sub Macro1()
Selection.HomeKey Unit:=wdStory
Do
With Selection.Find
.Text = "."
.Execute
.Forward = True
.Wrap = wdFindStop
End With
Selection.MoveLeft Unit:=wdWord, Count:=2, Extend:=wdExtend
chk = Arabic(Selection)
If chk <> "Fail" Then
Selection.TypeText chk
Selection.MoveRight Unit:=wdWord, Count:=2
Else
Selection.MoveRight Unit:=wdWord, Count:=2
End If
Loop
End Sub

Function Arabic(Roman)
'Declare variables
Dim Arabicvalues() As Integer
Dim convertedvalue As Long
Dim currentchar As String * 1
Dim i As Integer
Dim message As String
Dim numchars As Integer

'Trim argument, get argument length, and redimension array
Roman = LTrim(RTrim(Roman))
numchars = Len(Roman)
If numchars = 0 Then 'if arg is null, we're outta here
Arabic = ""
Exit Function
End If

ReDim Arabicvalues(numchars)
'Convert each Roman character to its Arabic equivalent
'If any character is invalid, display message and exit
For i = 1 To numchars
currentchar = Mid(Roman, i, 1)
Select Case UCase(currentchar)
Case "M": Arabicvalues(i) = 1000
Case "D": Arabicvalues(i) = 500
Case "C": Arabicvalues(i) = 100
Case "L": Arabicvalues(i) = 50
Case "X": Arabicvalues(i) = 10
Case "V": Arabicvalues(i) = 5
Case "I": Arabicvalues(i) = 1
Case Else
Arabic = "Fail"
Exit Function
End Select
Next i

'If any value is less than its neighbor to the right,
'make that value negative
For i = 1 To numchars - 1
If Arabicvalues(i) < Arabicvalues(i + 1) Then
Arabicvalues(i) = Arabicvalues(i) * -1
End If
Next i
'Build Arabic total
For i = 1 To numchars
Arabic = Arabic + Arabicvalues(i)
Next i

End Function

Pasquale
08-26-2006, 08:02 PM
Hallo, mdmackillop

Thank you.


Are there any Roman numerals which can be confused with words, other than "I"?

It is a very good macro.

pasquale