TGC Codebase Backup



Roman Numbers by Westmere

25th Jan 2011 11:48
Summary

Turns integers into roman numbers



Description

This function will turn an integer value between 1 and 3999 into a string containing the roman number (eg. roman$(2012) will return "MMXII" or roman$(1701) will return "MDCCI")



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem ********** roman Numbers **********
Function roman$(num)
txt$ = Str$(num)
t$ = Right$(txt$, 1)
i = val(t$)
txt2$ = ""
Select i
 Case 1: txt2$ = "I" : EndCase
 Case 2: txt2$ = "II" : EndCase
 Case 3: txt2$ = "III" : EndCase
 Case 4: txt2$ = "IV" : EndCase
 Case 5: txt2$ = "V" : EndCase
 Case 6: txt2$ = "VI" : EndCase
 Case 7: txt2$ = "VII" : EndCase
 Case 8: txt2$ = "VIII" : EndCase
 Case 9: txt2$ = "IX" : EndCase
 EndSelect

If Len(txt$) > 1  
 t$ = Left$(Right$(txt$, 2),1)  
 i = val(t$)
 Select i
  Case 1: txt2$ = "X"+txt2$ : EndCase
  Case 2: txt2$ = "XX"+txt2$ : EndCase
  Case 3: txt2$ = "XXX"+txt2$ : EndCase
  Case 4: txt2$ = "XL"+txt2$ : EndCase
  Case 5: txt2$ = "L"+txt2$ : EndCase
  Case 6: txt2$ = "LX"+txt2$ : EndCase
  Case 7: txt2$ = "LXX"+txt2$ : EndCase
  Case 8: txt2$ = "LXXX"+txt2$ : EndCase
  Case 9: txt2$ = "XC"+txt2$ : EndCase
  EndSelect
 EndIf 

If Len(txt$) > 2  
 t$ = Left$(Right$(txt$, 3),1)  
 i = val(t$)
 Select i
  Case 1: txt2$ = "C"+txt2$ : EndCase
  Case 2: txt2$ = "CC"+txt2$ : EndCase
  Case 3: txt2$ = "CCC"+txt2$ : EndCase
  Case 4: txt2$ = "CD"+txt2$ : EndCase
  Case 5: txt2$ = "D"+txt2$ : EndCase
  Case 6: txt2$ = "DC"+txt2$ : EndCase
  Case 7: txt2$ = "DCC"+txt2$ : EndCase
  Case 8: txt2$ = "DCCC"+txt2$ : EndCase
  Case 9: txt2$ = "CM"+txt2$ : EndCase
  EndSelect
 EndIf 

If Len(txt$) > 3  
 t$ = Left$(Right$(txt$, 4),1)  
 i = val(t$)
 Select i
  Case 1: txt2$ = "M"+txt2$ : EndCase
  Case 2: txt2$ = "MM"+txt2$ : EndCase
  Case 3: txt2$ = "MMM"+txt2$ : EndCase
  Case 4: txt2$ = "?"+txt2$ : EndCase
  Case 5: txt2$ = "?"+txt2$ : EndCase
  Case 6: txt2$ = "?"+txt2$ : EndCase
  Case 7: txt2$ = "?"+txt2$ : EndCase
  Case 8: txt2$ = "?"+txt2$ : EndCase
  Case 9: txt2$ = "?"+txt2$ : EndCase
  EndSelect
 EndIf 

EndFunction txt2$