Microsoft Small Basic
Program Listing:
Embed this in your website
<object id='sbapp' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='640' height='480'> <param name='source' value='http://smallbasic.com/program/ClientBin/SBWeb.xap'/> <param name='onError' value='onSilverlightError' /> <param name='background' value='white' /> <param name='minRuntimeVersion' value='3.0.40624.0' /> <param name='autoUpgrade' value='true' /> <param name='initParams' value='programId=SFP007' /> </object>
' RomanNumeral.sb
'This program was written by "Glennium"
Start
:
Bloc
(
)
' Loads Roman Numerals into Letters Array
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TextWindow
.
WriteLine
(
""
)
TextWindow
.
Write
(
"Please enter an integer from 1 to 3999; or ''Return'' to quit..."
)
i
=
TextWindow
.
ReadNumber
(
)
len
=
Text
.
GetLength
(
i
)
j
=
Math
.
Floor
(
i
)
If
i
=
0
Then
Goto
Endprog
ElseIf
i
<
0
Then
'tests if i is positive
TextWindow
.
WriteLine
(
"You must enter a number greater than Zero"
)
Goto
start
Elseif
i
>
j
Then
'tests if i is an integer
TextWindow
.
WriteLine
(
"You did not enter an integer."
)
Goto
start
Elseif
i
>=
4000
Then
TextWindow
.
WriteLine
(
"You must enter a number from 1 to 3999"
)
'TODO take care of this problem when using Graphics window...
EndIf
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
StripAndLoad
(
)
OutP
(
)
Goto
Start
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub
Bloc
Letters
[
1
]
[
1
]
=
"I''
Letters
[
1
]
[
2
]
=
"II"
Letters
[
1
]
[
3
]
=
"III"
Letters
[
1
]
[
4
]
=
"IV"
Letters
[
1
]
[
5
]
=
"V"
Letters
[
1
]
[
6
]
=
"VI"
Letters
[
1
]
[
7
]
=
"VII"
Letters
[
1
]
[
8
]
=
"VIII"
Letters
[
1
]
[
9
]
=
"IX"
Letters
[
1
]
[
0
]
=
""
Letters
[
2
]
[
1
]
=
"X"
Letters
[
2
]
[
2
]
=
"XX"
Letters
[
2
]
[
3
]
=
"XXX"
Letters
[
2
]
[
4
]
=
"XL"
Letters
[
2
]
[
5
]
=
"L"
Letters
[
2
]
[
6
]
=
"LX"
Letters
[
2
]
[
7
]
=
"LXX"
Letters
[
2
]
[
8
]
=
"LXXX"
Letters
[
2
]
[
9
]
=
"XC"
Letters
[
2
]
[
0
]
=
""
Letters
[
3
]
[
1
]
=
"C"
Letters
[
3
]
[
2
]
=
"CC"
Letters
[
3
]
[
3
]
=
"CCC"
Letters
[
3
]
[
4
]
=
"CD"
Letters
[
3
]
[
5
]
=
"D"
Letters
[
3
]
[
6
]
=
"DC"
Letters
[
3
]
[
7
]
=
"DCC"
Letters
[
3
]
[
8
]
=
"DCCC"
Letters
[
3
]
[
9
]
=
"CM"
Letters
[
3
]
[
0
]
=
""
Letters
[
4
]
[
1
]
=
"M"
Letters
[
4
]
[
2
]
=
"MM"
Letters
[
4
]
[
3
]
=
"MMM"
EndSub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub
OutP
TextWindow
.
WriteLine
(
""
)
For
B
=
len
to
1
Step
-
1
TextWindow
.
Write
(
Letters
[
B
]
[
Digits
[
B
]
]
)
EndFor
TextWindow
.
WriteLine
(
""
)
EndSub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub
StripAndLoad
X
=
Math
.
Power
(
10
,
len
-
1
)
' creates a multiplier to help strip off the digits
len2
=
len
'creates the second length variable so len will not be dammaged
For
Counter
=
len
To
1
Step
-
1
Z
=
math
.
Floor
(
i
/
X
)
'Z is the first digit in the line each iteration.
Digits
[
len2
]
=
Z
len2
=
len2
-
1
i
=
i
-
(
X
*
Z
)
X
=
X
/
10
EndFor
EndSub
Endprog
:
Copyright (c) Microsoft Corporation. All rights reserved.