How to convert letters to numbers?
Posted: Thu Jun 27, 2013 7:29 am
Hi, I'm doing an Arabic-Roman and vice versa numerals converter. When I thought I had everything complete, a problem appeared:
Now I have to convert each letter to it's corresponding value, and then Calculate the arabic number using a formula that I already have. The only thing I could think to accomplish this is the following:
7 different letters by 15 maximum letters = 105 lines of code. It's not optimal, but I would have been happy if it worked. Sadly, it didn't. An error that says something like "Types don't match" appears on the bolded part: r1$ = 1000
Is there a way to solve this by changing the variable type or do I have to rethink the whole thing differently?
Code: Select all
INPUT "Roman Number: ", r$
r1$ = MID$(r$, 1, 1)
r2$ = MID$(r$, 2, 1)
r3$ = MID$(r$, 3, 1)
...
r15$ = MID$(r$, 15, 1)
'This takes each of the input characters into a different variable. I made 15 because that's the maximum amount of numbers in the Roman numerals (MMMDCCCLXXXVIII)
Code: Select all
IF r1$ = "M" then r1$ = 1000
...
IF r1$ = "C" then r1$ = 100
...
IF r1$ = "X" then r1$ = 10
...
Is there a way to solve this by changing the variable type or do I have to rethink the whole thing differently?