INPUT "Roman number ? "; R$
R$ = UPPER$(R$)
PRINT R$
D = 0
FOR i = 1 TO 13
READ Rom$, Dec
DO
IF LEFT$(R$, LEN(Rom$)) = Rom$ THEN
D = D + Dec
R$ = MID$(R$, LEN(Rom$)+1)
ELSE
EXIT DO
END IF
LOOP
NEXT i
PRINT D
END
DATA "M", 1000, "CM", 900, "CD", 400, "D", 500, "XC", 90, "C", 100, "XL", 40, "L", 50, "X", 10, "IX", 9, "IV", 4, "V", 5, "I", 1
' ROMAN-DECIMAL.BAS LBB 3.04
' ===================
'conversion from roman numbers to decimal numbers, and back
'positive integers only, max 9999 or "MMMMMMMMMCMXCIX"
'seems enough for quite a while
NOMAINWIN
'--- setting the controls
RadioButton #w.radio1, "ROMAN => DECIMAL", [EnterRomanNumber], , 20, 50, 150, 20
StyleBits #w.radio1, _WS_BORDER, 0,0,0
TextBox #w.ROMAN, 180, 50, 160, 25
StyleBits #w.ROMAN, _ES_UPPERCASE, 0, 0, 0
RadioButton #w.radio2, "DECIMAL => ROMAN", [EnterDecimalNumber], , 20, 100, 150, 20
StyleBits #w.radio2, _WS_BORDER, 0,0,0
TextBox #w.DECIMAL, 180, 100, 160, 25
StyleBits #w.DECIMAL, _ES_NUMBER, 0, 0, 0
Button #w.RAZ, "RESET", [Reset], UL, 50, 180, 50, 50
StyleBits #w.RESET, _WS_DLGFRAME, 0, 0, 0
Button #w.Default, "CALC", [Toggle], UL, 155, 180, 50, 50
StyleBits #w.Default, _WS_DLGFRAME, 0, 0, 0
Button #w.Quit, "QUIT", [EndProgram], UL, 260, 180, 50, 50
StyleBits #w.Quit, _WS_DLGFRAME, 0, 0, 0
'--- opening the window
UpperLeftX = 100: UpperLeftY = 150: WindowHeight = 300: WindowWidth = 370
OPEN "ROMAN 2 DECIMAL & DECIMAL 2 ROMAN" FOR DIALOG AS #w
PRINT #w "Font Arial 10"
PRINT #w "TrapClose [EndProgram]"
PRINT #w.radio1, "set"
PRINT #w.ROMAN, "!enable"
PRINT #w.ROMAN, "!setfocus"
WAIT
'--- and now the subroutines
[EnterRomanNumber]
D = 0
R$ = ""
PRINT #w.DECIMAL, ""
PRINT #w.DECIMAL, "!disable" 'avoiding unwanted input
PRINT #w.radio1, "set"
PRINT #w.ROMAN, "!enable"
PRINT #w.ROMAN, ""
PRINT #w.ROMAN, "!setfocus"
WAIT
[EnterDecimalNumber]
D = 0
R$ = ""
PRINT #w.ROMAN, ""
PRINT #w.ROMAN, "!disable" 'avoiding unwanted input
PRINT #w.DECIMAL, "!enable"
PRINT #w.DECIMAL, "!setfocus"
PRINT #w.DECIMAL, ""
WAIT
[Toggle]
PRINT #w.ROMAN, "!contents? R$";
IF R$ <> "" THEN GOTO [Rom2Dec]
PRINT #w.DECIMAL, "!contents? D$";
IF D$ <> "" THEN GOTO [Dec2Rom]
WAIT
''' --------------------------- ROMAN TO DECIMAL -----------------
[Rom2Dec]
RESTORE [RomanData]
D = 0
FOR i = 1 TO 13
READ Rom$, Dec
DO
IF LEFT$(R$, LEN(Rom$)) = Rom$ THEN
D = D + Dec
R$ = MID$(R$, LEN(Rom$)+1)
ELSE
EXIT DO
END IF
LOOP
NEXT i
IF R$ <> "" THEN
NOTICE "Error" + CHR$(13) + "Wrong Roman Number"
ELSE
PRINT #w.DECIMAL, "!enable"
PRINT #w.DECIMAL, STR$(D)
END IF
WAIT
''' -------------------- DECIMAL TO ROMAN ------------
[Dec2Rom]
R$ = ""
D = VAL(D$)
RESTORE [DecimalData]
FOR i = 1 TO 13
IF D = 0 THEN EXIT FOR
READ Rom$, Dec
DO
IF D >= Dec THEN
R$ = R$ + Rom$
D = D - Dec
ELSE
EXIT DO
END IF
LOOP
NEXT i
PRINT #w.ROMAN, "!enable"
PRINT #w.ROMAN, R$
WAIT
[Reset]
PRINT #w.radio2, "reset"
PRINT #w.radio1, "set"
PRINT #w.DECIMAL, ""
PRINT #w.ROMAN, "!enable"
PRINT #w.ROMAN, ""
PRINT #w.ROMAN, "!setfocus"
R$ = ""
D = 0
WAIT
[EndProgram]
CLOSE #w
END
[RomanData]
DATA "M", 1000, "CM", 900, "CD", 400, "D", 500, "XC", 90, "C", 100, "XL", 40, "L", 50, "X", 10, "IX", 9, "IV", 4, "V", 5, "I", 1
[DecimalData]
DATA "M", 1000, "CM", 900, "D", 500, "CD", 400, "C", 100, "XC", 90, "L", 50, "XL", 40, "X", 10, "IX", 9, "V", 5, "IV", 4, "I", 1
INPUT "Roman number ? "; R$
R$ = UPPER$(R$)
PRINT R$
D = 0
FOR i = 1 TO 15
READ Rom$, Dec
DO
IF LEFT$(R$, LEN(Rom$)) = Rom$ THEN
D = D + Dec
R$ = MID$(R$, LEN(Rom$)+1)
ELSE
EXIT DO
END IF
LOOP
NEXT i
PRINT D
END
DATA "MDCD", 1900,"M", 1000, "CM", 900, "CD", 400, "D", 500, "XC", 90, "C", 100, "XL", 40, "L", 50, "X", 10, "IIX", 8, "IX", 9, "IV", 4, "V", 5, "I", 1