Wednesday, November 27, 2019

Roman To Decimal Converter in Visual Basic NET

I wrote this program to ask the user to give a value in roman numerals and then the program will convert from roman numerals into decimal equivalent using Microsoft Visual Basic NET as my programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City, Negros Occidental I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My Facebook address is https://www.facebook.com/profile.php?...

My personal website is http://www.jakerpomperada.com

My programming website is http://www.jakerpomperada.blogspot.com

I am also a book author you can purchase my books on computer programming and information technology in the following links below.

https://www.mindshaperspublishing.com/

https://www.unlimitedbooksph.com/

Thank you very much for your help and support.





Sample Program Output


Program Listing

Public Class Form1

    Private Enum RomanDigit
        I = 1
        V = 5
        X = 10
        L = 50
        C = 100
        D = 500
        M = 1000
    End Enum

    Public Shared Function RomanToNumbers(ByVal roman As String) As Integer
        roman = roman.ToUpper().Trim()
        If roman = "N" Then
            Return 0
        End If

        Dim ptr As Integer = 0
        Dim values As New ArrayList()
        Dim maxDigit As Integer = 1000
        While ptr < roman.Length
            Dim numeral As Char = roman(ptr)
            Dim digit As Integer = CInt([Enum].Parse(GetType(RomanDigit), numeral.ToString()))

            Dim nextDigit As Integer = 0
            If ptr < roman.Length - 1 Then
                Dim nextNumeral As Char = roman(ptr + 1)
                nextDigit = CInt([Enum].Parse(GetType(RomanDigit), nextNumeral.ToString()))

                If nextDigit > digit Then
                    maxDigit = digit - 1
                    digit = nextDigit - digit
                    ptr += 1
                End If
            End If

            values.Add(digit)
            ptr += 1
        End While

        Dim total As Integer = 0
        For Each digit As Integer In values
            total += digit
        Next

        Return total
    End Function


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If MsgBox("Are you sure you want to quit?", MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton2, "Close application") = Windows.Forms.DialogResult.Yes Then
            Me.Close()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim display As Double

        display = RomanToNumbers(TextBox1.Text)
        MsgBox("The Decimal Equivalent is " & display & ".", vbInformation, "The Result")
        TextBox1.Text = ""
        TextBox1.Focus()
    End Sub
End Class


No comments:

Post a Comment