|
Тема |
Re: въпрос за програмен код на VB [re: mixi] |
|
Автор |
fiffy () |
|
Публикувано | 06.06.06 22:03 |
|
|
Google: visual basic roman to arabic
Result: http://www.vb-helper.com/howto_roman_arabic.html
Text:
Private Function RomanToArabic(ByVal roman As String) As _
Long
Dim i As Integer
Dim ch As String
Dim result As Long
Dim new_value As Long
Dim old_value As Long
roman = UCase$(roman)
old_value = 1000
For i = 1 To Len(roman)
' See what the next character is worth.
ch = Mid$(roman, i, 1)
Select Case ch
Case "I"
new_value = 1
Case "V"
new_value = 5
Case "X"
new_value = 10
Case "L"
new_value = 50
Case "C"
new_value = 100
Case "D"
new_value = 500
Case "M"
new_value = 1000
End Select
' See if this character is bigger
' than the previous one.
If new_value > old_value Then
' The new value > the previous one.
' Add this value to the result
' and subtract the previous one twice.
result = result + new_value - 2 * old_value
Else
' The new value <= the previous one.
' Add it to the result.
result = result + new_value
End If
old_value = new_value
Next i
RomanToArabic = result
End Function
|
| |
|
|
|