Convert to Roman Numerals

# Thread: Convert to Roman Numerals

1. John D Guest

## Convert to Roman Numerals

I am looking for a function that will convert an interger to a Roman Numeral.<BR><BR>Thanks,<BR>John

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Wow! What fun!

So much fun, I decided I had to write one!<BR><BR>LIMITATION: This version will only convert numbers up to 3,899.<BR><BR>Tell me the Roman Numeral character for 5,000 if you want to go higher!<BR><BR>********* FILE: RomanNumerals.asp **********<BR><BR>&lt;HTML&#062;&lt;BODY&#062;<BR> <BR>&lt;%<BR>Function oneDigit( digit, ones, five, ten )<BR>&nbsp;&nbsp;&nbsp;&nbsp;If digit = 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;oneDigit = ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;ElseIf digit = 9 Then <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;oneDigit = Left(ones,1) & ten<BR>&nbsp;&nbsp;&nbsp;&nbsp;ElseIf digit = 4 Then <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;oneDigit = Left(ones,1) & five<BR>&nbsp;&nbsp;&nbsp;&nbsp;ElseIf digit &#062;= 5 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;oneDigit = five & Left(ones,digit-5)<BR>&nbsp;&nbsp;&nbsp;&nbsp;Else<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oneDigit = Left(ones,digit)<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>End Function<BR><BR>Function RomanNumeral( ByVal num )<BR>&nbsp;&nbsp;&nbsp;&nbsp;If num &lt; 0 OR num &#062; 3899 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;RomanNumeral = "ERROR"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;Exit Function<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;Dim result<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = oneDigit( num 1000, "MMMM", "?", "?" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 1000<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num 100, "CCCC", "D", "M" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 100<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num 10, "XXXX", "L", "C" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 10<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num, "IIII", "V", "X" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;RomanNumeral = result<BR>End Function<BR>%&#062;<BR><BR>A demo of the Roman Numeral version of various values:<BR>&lt;UL&#062;<BR>&lt;LI&#062;3 = &lt;% = RomanNumeral(3) %&#062;<BR>&lt;LI&#062;4 = &lt;% = RomanNumeral(4) %&#062;<BR>&lt;LI&#062;7 = &lt;% = RomanNumeral(7) %&#062;<BR>&lt;LI&#062;9 = &lt;% = RomanNumeral(9) %&#062;<BR>&lt;LI&#062;11 = &lt;% = RomanNumeral(11) %&#062;<BR>&lt;LI&#062;22 = &lt;% = RomanNumeral(22) %&#062;<BR>&lt;LI&#062;33 = &lt;% = RomanNumeral(33) %&#062;<BR>&lt;LI&#062;44 = &lt;% = RomanNumeral(44) %&#062;<BR>&lt;LI&#062;49 = &lt;% = RomanNumeral(49) %&#062;<BR>&lt;LI&#062;50 = &lt;% = RomanNumeral(50) %&#062;<BR>&lt;LI&#062;55 = &lt;% = RomanNumeral(55) %&#062;<BR>&lt;LI&#062;89 = &lt;% = RomanNumeral(89) %&#062;<BR>&lt;LI&#062;90 = &lt;% = RomanNumeral(90) %&#062;<BR>&lt;LI&#062;99 = &lt;% = RomanNumeral(99) %&#062;<BR>&lt;LI&#062;429 = &lt;% = RomanNumeral(429) %&#062;<BR>&lt;LI&#062;1844 = &lt;% = RomanNumeral(1844) %&#062;<BR>&lt;LI&#062;3899 = &lt;% = RomanNumeral(3899) %&#062;<BR>&lt;/UL&#062;<BR><BR>&lt;/BODY&#062;&lt;/HTML&#062;<BR><BR>******************************** *********<BR><BR>Hey! It worked!<BR>

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## An improvement...

Somebody reminded me that one convention is to put a LINE over the top of a letter to indicate that you want its value multiplied by 1000. Well, putting lines on *TOP* of letters is tough in HTML, but putting the line *below* is easy enough. So if you&#039ll accept that compromise....<BR><BR>*********** RomanNumeralsII.asp ***********<BR><BR>&lt;HTML&#062;&lt;BODY&#062;<BR ><BR>&lt;%<BR>Function oneDigit( digit, one, five, ten )<BR>&nbsp;&nbsp;&nbsp;&nbsp;If digit = 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;oneDigit = ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;ElseIf digit = 9 Then <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;oneDigit = one & ten<BR>&nbsp;&nbsp;&nbsp;&nbsp;ElseIf digit = 4 Then <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;oneDigit = one & five<BR>&nbsp;&nbsp;&nbsp;&nbsp;Else<BR> Dim temp<BR> temp = ""<BR> If digit &#062;= 5 Then temp = five<BR> Dim i<BR> For i = 1 To ( digit MOD 5 )<BR> temp = temp & one<BR> Next<BR> oneDigit = temp<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>End Function<BR><BR>Function RomanNumeral( ByVal num )<BR>&nbsp;&nbsp;&nbsp;&nbsp;If num &lt; 0 OR num &#062; 39999999 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;RomanNumeral = "ERROR"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;Exit Function<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;Dim result<BR> result = ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num 1000000, "&lt;U&#062;M&lt;/U&#062;", "&lt;U&#062;?&lt;/U&#062;", "&lt;U&#062;?&lt;/U&#062;" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 1000000<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num 100000, "&lt;U&#062;C&lt;/U&#062;", "&lt;U&#062;D&lt;/U&#062;", "&lt;U&#062;M&lt;/U&#062;" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 100000<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num 10000, "&lt;U&#062;X&lt;/U&#062;", "&lt;U&#062;L&lt;/U&#062;", "&lt;U&#062;C&lt;/U&#062;" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 10000<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num 1000, "M", "&lt;U&#062;V&lt;/U&#062;", "&lt;U&#062;X&lt;/U&#062;" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 1000<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num 100, "C", "D", "M" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 100<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num 10, "X", "L", "C" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;num = num MOD 10<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = result & oneDigit( num, "I", "V", "X" )<BR>&nbsp;&nbsp;&nbsp;&nbsp;RomanNumeral = result<BR>End Function<BR>%&#062;<BR><BR>A demo of the Roman Numeral version of various values:<BR>&lt;UL&#062;<BR>&lt;LI&#062;3 = &lt;% = RomanNumeral(3) %&#062;<BR>&lt;LI&#062;4 = &lt;% = RomanNumeral(4) %&#062;<BR>&lt;LI&#062;7 = &lt;% = RomanNumeral(7) %&#062;<BR>&lt;LI&#062;9 = &lt;% = RomanNumeral(9) %&#062;<BR>&lt;LI&#062;11 = &lt;% = RomanNumeral(11) %&#062;<BR>&lt;LI&#062;22 = &lt;% = RomanNumeral(22) %&#062;<BR>&lt;LI&#062;33 = &lt;% = RomanNumeral(33) %&#062;<BR>&lt;LI&#062;44 = &lt;% = RomanNumeral(44) %&#062;<BR>&lt;LI&#062;49 = &lt;% = RomanNumeral(49) %&#062;<BR>&lt;LI&#062;50 = &lt;% = RomanNumeral(50) %&#062;<BR>&lt;LI&#062;55 = &lt;% = RomanNumeral(55) %&#062;<BR>&lt;LI&#062;89 = &lt;% = RomanNumeral(89) %&#062;<BR>&lt;LI&#062;90 = &lt;% = RomanNumeral(90) %&#062;<BR>&lt;LI&#062;99 = &lt;% = RomanNumeral(99) %&#062;<BR>&lt;LI&#062;429 = &lt;% = RomanNumeral(429) %&#062;<BR>&lt;LI&#062;1844 = &lt;% = RomanNumeral(1844) %&#062;<BR>&lt;LI&#062;3899 = &lt;% = RomanNumeral(3899) %&#062;<BR>&lt;LI&#062;11111 = &lt;% = RomanNumeral(11111) %&#062;<BR>&lt;LI&#062;222222 = &lt;% = RomanNumeral(222222) %&#062;<BR>&lt;LI&#062;3333333 = &lt;% = RomanNumeral(3333333) %&#062;<BR>&lt;LI&#062;3999999 = &lt;% = RomanNumeral(3999999) %&#062;<BR>&lt;/UL&#062;<BR><BR>&lt;/BODY&#062;&lt;/HTML&#062;<BR><BR>******************************** ******<BR><BR>And now I think I really will put it to rest!<BR><BR>Note that the max number is now 3,999,999.<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## I could not help myself...

Okay, another way to improve it...albeit just slightly...<BR><BR>******** RomanNumeralsIII.asp *******************<BR>&lt;HTML&#062;&lt;BODY&#062 ;<BR><BR>&lt;%<BR>Digits = Array( "I","V","X","L","C","D","M", _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;"&lt;U&#062;V&lt;/U&#062;","&lt;U&#062;X&lt;/U&#062;","&lt;U&#062;L&lt;/U&#062;", _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;"&lt;U&#062;C&lt;/U&#062;","&lt;U&#062;D&lt;/U&#062;","&lt;U&#062;M&lt;/U&#062;", _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;"?","?" _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp; )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR >Function RomanNumeral( ByVal num )<BR>&nbsp;&nbsp;&nbsp;&nbsp;Dim one, five, ten, digit, power, startD, temp<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;If num &lt; 0 OR num &#062; 39999999 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;RomanNumeral = "ERROR"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;Exit Function<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;Dim result<BR>&nbsp;&nbsp;&nbsp;&nbsp;result = ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;For power = 1 to 7<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;digit = num MOD 10<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;startD = (power-1) * 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;one = Digits(startD)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;five = Digits(startD+1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ten = Digits(startD+2)<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;If digit = 9 Then <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;result = one & ten & result<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;ElseIf digit = 4 Then <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;result = one & five & result<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;temp = ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;If digit &#062;= 5 Then temp = five<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;For i = 1 To ( digit MOD 5 )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;temp = temp & one<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Next<BR>&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;result = temp & result<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;End If<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;num = num 10<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;If num = 0 Then Exit For &#039 not needed, but why not?<BR>&nbsp;&nbsp;&nbsp;&nbsp;Next<BR>&nbsp;&nbs p;&nbsp;&nbsp;RomanNumeral = result<BR>End Function<BR>%&#062;<BR><BR>A demo of the Roman Numeral version of various values:<BR>&lt;UL&#062;<BR>&lt;LI&#062;3 = &lt;% = RomanNumeral(3) %&#062;<BR>&lt;LI&#062;4 = &lt;% = RomanNumeral(4) %&#062;<BR>&lt;LI&#062;7 = &lt;% = RomanNumeral(7) %&#062;<BR>&lt;LI&#062;9 = &lt;% = RomanNumeral(9) %&#062;<BR>&lt;LI&#062;11 = &lt;% = RomanNumeral(11) %&#062;<BR>&lt;LI&#062;22 = &lt;% = RomanNumeral(22) %&#062;<BR>&lt;LI&#062;33 = &lt;% = RomanNumeral(33) %&#062;<BR>&lt;LI&#062;44 = &lt;% = RomanNumeral(44) %&#062;<BR>&lt;LI&#062;49 = &lt;% = RomanNumeral(49) %&#062;<BR>&lt;LI&#062;50 = &lt;% = RomanNumeral(50) %&#062;<BR>&lt;LI&#062;55 = &lt;% = RomanNumeral(55) %&#062;<BR>&lt;LI&#062;89 = &lt;% = RomanNumeral(89) %&#062;<BR>&lt;LI&#062;90 = &lt;% = RomanNumeral(90) %&#062;<BR>&lt;LI&#062;99 = &lt;% = RomanNumeral(99) %&#062;<BR>&lt;LI&#062;429 = &lt;% = RomanNumeral(429) %&#062;<BR>&lt;LI&#062;1844 = &lt;% = RomanNumeral(1844) %&#062;<BR>&lt;LI&#062;3899 = &lt;% = RomanNumeral(3899) %&#062;<BR>&lt;LI&#062;11111 = &lt;% = RomanNumeral(11111) %&#062;<BR>&lt;LI&#062;222222 = &lt;% = RomanNumeral(222222) %&#062;<BR>&lt;LI&#062;3333333 = &lt;% = RomanNumeral(3333333) %&#062;<BR>&lt;LI&#062;3999999 = &lt;% = RomanNumeral(3999999) %&#062;<BR>&lt;/UL&#062;<BR><BR>&lt;/BODY&#062;&lt;/HTML&#062;<BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
19,082

## Ported to JScript

so it can be used client-side or server-side<BR><BR>function getNumeral(intNum) {<BR> var arrDigits = new Array("I","V","X","L","C","D","M", "&#060;U&#062;V&#060;/U&#062;","&#060;U&#062;X&#060;/U&#062;","&#060;U&#062;L&#060;/U&#062;", "&#060;U&#062;C&#060;/U&#062;","&#060;U&#062;D&#060;/U&#062;","&#060;U&#062;M&#060;/U&#062;", "?","?"); <BR> if(intNum&#060;0&#124&#124intNum&#062;39999999) {<BR> return "Error";<BR> }<BR> var result = &#039&#039;<BR> for(var x=0;x&#060;7;x++) {<BR> intDig = intNum % 10;<BR> intStartD = x * 2;<BR> one = arrDigits[intStartD];<BR> five = arrDigits[intStartD+1];<BR> ten = arrDigits[intStartD+2];<BR> if(intDig==9) {<BR> result = one + ten + result;<BR> } else if(intDig==4) {<BR> result = one + five + result;<BR> } else {<BR> var temp = "";<BR> if(intDig &#062;= 5) { <BR> temp = five;<BR> } <BR> for(i=1;i&#060;=(intDig%5);i++) {<BR> temp += one;<BR> }<BR> result = temp + result; <BR> }<BR> intNum = parseInt(intNum/10);<BR> } <BR> return result ; <BR>}

6. John D Guest

## I acutally made my own

On this board, I actually made my own...<BR>and Bill thanks for all the help, but you might acutually like this one better, because it is infinitely usable... all you need to do is extend the array... check it out<BR><BR>Function makeRoman(byVal theNumber)<BR> Dim temp, i, j, strLength, strNumber, tempChar, rPos &#039 (reverse position)<BR> Dim RomanArray(9)<BR> RomanArray(1) = "I"<BR> RomanArray(2) = "V"<BR> RomanArray(3) = "X"<BR> RomanArray(4) = "L"<BR> RomanArray(5) = "C"<BR> RomanArray(6) = "D"<BR> RomanArray(7) = "M"<BR> RomanArray(8) = "Q"<BR> RomanArray(9) = "P" <BR> <BR> If theNumber &#062; 0 And theNumber &#060; 10000 Then<BR> strNumber = cStr(theNumber)<BR> strLength = len(strNumber)<BR> <BR> i = strLength<BR> Do while i &#062; 0<BR> rPos = (strLength - i) * 2 + 1<BR> tempChar = Mid(strNumber, i, 1)<BR> Select Case tempChar<BR> Case 1<BR> temp = RomanArray(rPos) & temp<BR> Case 2<BR> temp = RomanArray(rPos) & RomanArray(rPos) & temp<BR> Case 3<BR> temp = RomanArray(rPos) & RomanArray(rPos) & RomanArray(rPos) & temp<BR> Case 4<BR> temp = RomanArray(rPos) & RomanArray(rPos + 1) & temp<BR> Case 5<BR> temp = RomanArray(rPos + 1) & temp<BR> Case 6<BR> temp = RomanArray(rPos + 1) & RomanArray(rPos) & temp<BR> Case 7<BR> temp = RomanArray(rPos + 1) & RomanArray(rPos) & RomanArray(rPos) & temp<BR> Case 8<BR> temp = RomanArray(rPos + 1) & RomanArray(rPos) & RomanArray(rPos) & RomanArray(rPos) & temp<BR> Case 9<BR> temp = RomanArray(rPos) + RomanArray(rPos + 2) & temp<BR> End Select<BR> <BR> i = i - 1<BR> Loop<BR> <BR><BR> makeRoman = temp<BR> Else<BR> makeRoman = "Bad Number"<BR> End If<BR>End Function

7. John D Guest

## ohh

I guess everyone is using arrays! <BR>Thanks for the help!

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Interesting how close we are...

If I might suggest a couple of improvements:<BR><BR>(1) Don&#039t create the array of roman letters *inside* your function. When you do that, the array has to be created each time the function is called. Since the array is constant, just create it outside of any function.<BR><BR>(2) Use the "shorthand" way of creating an array. Faster and a *lot* less code:<BR><BR>Dim RomanArray<BR>RomanArray = Array("I","V","X","L","C","D","M","P","Q")<BR><BR>[That makes an array starting at element zero, so you&#039ll need to change to <BR>rPos = (strLength - i) * 2 <BR>or, if you like 1-based arrays, put in a dummy value for the first array value entry.]<BR><BR>(3) This one *really* is not important, but...<BR><BR>Instead of doing:<BR><BR>i = strLength<BR>Do while i &#062; 0<BR>...<BR>i = i - 1<BR>Loop<BR><BR>You can do:<BR><BR>For i = strLength To 1 Step -1<BR>...<BR>Next<BR><BR>(4) I think I like your way of simply putting each digit value in its own case. Only a bit more code, and better efficiency. One other minor efficiency improvement: Your SELECT CASE value is a STRING (the result of the MID call) but the individual cases are integers. Either change the SELECT CASE value to an integer [ SELECT CASE CInt(Mid(strNumber, i, 1)) ] or make the individual case values be string [ Case "5", etc. ]. <BR><BR>(3) and (4) are *REALLY* nitpicky stuff. But since this question has turned into a fun programming exercise, why shouldn&#039t we take it all the way!<BR><BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Ported to JScript

This would make a fun variation on a HITS counter for a site, wouldn&#039t it?<BR><BR>Have you seen my "words" version, on www.clearviewDesign.com ?<BR><BR>Hmmmm....<BR><BR>Hey! How about an onscreen clock, done with JS, that shows the time in Roman Numerals? That would be a kick.<BR><BR>

10. Steve Cimino Guest

## Uh, bill?

&#062;&#062;This would make a fun variation on a HITS counter for a site, wouldn&#039t it?<BR><BR>How about rather annoying? I used to hate those damned copyrights on movie credits to determine what year the movie came out.<BR><BR>&#062;&#062;Hey! How about an onscreen clock, done with JS, that shows the time in Roman Numerals? That would be a kick.<BR><BR>I think it&#039s time for a vacation Bill ;)<BR><BR>&#060;WISEASS REMARK&#062;Deprivation of sleep is considered torture. Makes the brain go haywire. Wasn&#039t there some guy in the 1950s who went 200 hours without sleep and went nutso? Learn from others&#039 mistakes! &#060;/WISEASS REMARK&#062;

#### Posting Permissions

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