View Single Post
  #4 (permalink)  
Old April 25th, 2016, 09:44 AM
Maximilian Maximilian is offline
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2016
Location: Buffalo, NY
Posts: 4
Thanks: 4
Thanked 0 Times in 0 Posts

Dr. Stephens, thank you very much for your guidance. Unfortunately, you are giving too much credit to my current programming abilities. I was able to cobble together a program that actually runs, but its functionality at this stage is very limited, as follows:

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim RomInp As String 'User input
        Dim RomNum As Integer = 0 'Final answer
        Dim RomNumEl As String 'Each letter in user input
        Dim RomNumElNum As Integer 'Each letter in user input converted to its numeric value
        Dim Prompt1 As String = "Enter a Roman numeral in capitals"
        Dim ErrMess1 As String = "Please enter a valid Roman numeral!"
        RomInp = InputBox(Prompt1, "Roman numeral")
        If Not RomInp.Contains("I") And Not RomInp.Contains("V") And Not RomInp.Contains("X") And Not RomInp.Contains("L") And Not RomInp.Contains("C") And Not RomInp.Contains("D") And Not RomInp.Contains("M") Then
            GoTo Main 'Reject invalid input from user
        End If
        For Each i In RomInp
            RomNumEl = Microsoft.VisualBasic.Right(RomInp, 1)
            If RomNumEl = "I" Then
                RomNumElNum = 1
            ElseIf RomNumEl = "V" Then
                RomNumElNum = 5
            ElseIf RomNumEl = "X" Then
                RomNumElNum = 10
            ElseIf RomNumEl = "L" Then
                RomNumElNum = 50
            ElseIf RomNumEl = "C" Then
                RomNumElNum = 100
            ElseIf RomNumEl = "D" Then
                RomNumElNum = 500
            ElseIf RomNumEl = "M" Then
                RomNumElNum = 1000
            End If
            RomNum += RomNumElNum
        Next i
        MsgBox(RomNum, , "Arabic equivalent")
    End Sub
End Class
For single letters or series of the same type of letter it gives correct answers, such as "3" for "III," but it gets confused if there is a combination of different letters. For example, it answers "4" for "XIII," "10" for "XV" and "300" for "MDC," I don't know why.

I tried adding a line for subtraction of a smaller number from the whole, but cannot get that version to run at all. So, when I add at the end of the loop:

If i + 1 < i Then
                RomNum -= RomNumElNum
                RomNum += RomNumElNum
            End If
        Next i
the program does not compile anymore, and I get a message "Operator '+' is not defined for types 'Char' and 'Integer'." I think I'm not using correct syntax for the loop. Is there any way you could tell me how to fix it?

Thank you very much for your kind help.

Best regards,