Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27381

VS 2010 Help With Code for Roman Numeral Calculator

$
0
0
Hi!

I have an assignment due in for school and I have hit a brick wall.

This is the task

HTML Code:

TASK
Roman numerals continue to be used for certain limited purposes such as copyright dates.  The symbols used are; I – 1; V – 5; X – 10; L – 50; C – 100; D – 500 and M – 1000.

One definition of Roman numerals is:

•        The letters must be in descending order of value.
•        The value of the number is the sum of all the letters.
•        A letter must not be repeated if it can be replaced by another letter.

This is known as the additive rule and is the only rule to be used in this assessment.  Note that Roman numerals are always integers and cannot have fractional values.

For example:

•        MCX = 1000 + 100 +10 = 1110
•        MXC is invalid because of the wrong order.
•        IIII = 1 + 1 + 1 + 1 = 4
•        IIIII is invalid because it can be replaced with V

A manufacturing company wishes to make a new calculator that allows the user to input two numbers in Arabic decimal form and displays the numbers in Roman numeral form.  The calculator then allows a user to add or subtract the two numbers, displaying the result in both Arabic decimal and Roman numeral form. 
NB
The calculator should not allow the result of a subtraction to be zero or a negative number.

So I have managed to design a working calculator (except the minus button is always giving me a negative answer for some reason).

I have added a second display on my form 'txtDisplay2' and need help with code that would display the contents of 'txtDisplay' in 'txtDisplay2' as Roman Numerals.

Below is my code so far

HTML Code:

Public Class Form1


    Dim total1 As Integer
    Dim total2 As Integer




    Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
        txtDisplay.Text = txtDisplay.Text & btnOne.Text
    End Sub

    Private Sub btnZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZero.Click
        txtDisplay.Text = txtDisplay.Text & btnZero.Text
    End Sub

    Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click
        txtDisplay.Text = txtDisplay.Text & btnTwo.Text
    End Sub

    Private Sub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click
        txtDisplay.Text = txtDisplay.Text & btnThree.Text
    End Sub

    Private Sub btnFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFour.Click
        txtDisplay.Text = txtDisplay.Text & btnFour.Text
    End Sub

    Private Sub btnFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFive.Click
        txtDisplay.Text = txtDisplay.Text & btnFive.Text
    End Sub

    Private Sub btnSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSix.Click
        txtDisplay.Text = txtDisplay.Text & btnSix.Text
    End Sub

    Private Sub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click
        txtDisplay.Text = txtDisplay.Text & btnSeven.Text
    End Sub

    Private Sub btnEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEight.Click
        txtDisplay.Text = txtDisplay.Text & btnEight.Text
    End Sub

    Private Sub btnNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNine.Click
        txtDisplay.Text = txtDisplay.Text & btnNine.Text
    End Sub


    Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click

        total1 = total1 + Val(txtDisplay.Text)
        txtDisplay.Clear()

    End Sub


    Private Sub btnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquals.Click

        total2 = total1 + Val(txtDisplay.Text)
        txtDisplay.Text = total2
        total1 = 0

   
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtDisplay.Clear()
    End Sub


    Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click

        total1 = total1 - Val(txtDisplay.Text)
        txtDisplay.Clear()

    End Sub


End Class

Also here is what it looks like
https://gyazo.com/9b057c7943d3aed497d6c237b98a0680

Thank you for any help!

Viewing all articles
Browse latest Browse all 27381

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>