Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have been able to complete the code through step 9, but am having trouble with step 10. My code so far is at the

I have been able to complete the code through step 9, but am having trouble with step 10. My code so far is at the bottom.

In Visual Basic, perform the following:

  • Create a form divided vertically in two halves with right and left panels
    1. In the left panel create the following controls: (the label or the value of the control will be in "" and the type of the control will in []
      1. "First Number" [textbox]
      2. "Second number" [textbox]
      3. "Result" [textbox] - read only
      4. "+" [push button] "-" [push button] "/" [push button] "*" [push button]
      5. "Save" [push button] "Display" [push button]
    2. The user will enter two numbers
      • the "First Number"
      • the "Second Number",
    3. Then press the "+" for addition, "-" for subtraction, "*" for multiplication and "/" for division
    4. The result will be displayed in the result [textbox],
    5. If the user clicked "[save]" then the operation can be displayed in the right panel when the user press [Display]
    6. Create two main classes to perform the operations above:
      • Create a class for the math ( "+","-") operations -- name the class "MathOp"
      • Extend the class using inheritance to include ("*","/") name the class "MathOp2"
        • Create the following class/function:
          • when a line from the list box is selected, the user should be able to modify the values/operations and save it to the listbox/database Lets say the user clicked on 1+3=4 , the values 1,3 should be displayed in the input text boxes.
    7. Add "clear" [push button] on the right panel to clear the content in the results listbox
    8. Trap all the errors and set the focus to the appropriate control after the error occurred
    9. The result in the listbox should contain the operations, I.E. the listbox results should look something like this 1+1=2 1*2=2 and so on
    10. Save and retrieve the operations in Ms. Access database
      • Create a table to save the operations
      • Create the necessary fields for the table
      • Create a button to save the content of the listbox to the database
      • Create a button to retrieve the content of the table into the listbox
        • The table in the database should not exceed 10 records. When saved, the table should be cleared and replaced with the new operations
      • When a line from the list box is selected, the user should be able to modify the values/operations and save it to the listbox/database

My code so far:

Option Explicit On

Option Strict Off

Option Infer Off

Public Class Calculator

'variables

Dim mathOps As MathOp2 = New MathOp2()

Dim int1stNum As Integer = 0

Dim int2ndNum As Integer = 0

Dim intResult As Integer = 0

Dim strSymbol As String

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click

'Error checking

If (txtFirstNumber.Text Is "" Or txtSecondNumber.Text Is "") Then

MessageBox.Show("Please enter the values")

Else

int1stNum = Integer.Parse(txtFirstNumber.Text)

strSymbol = "+"

int2ndNum = Integer.Parse(txtSecondNumber.Text)

'Calls the class

intResult = mathOps.Add(int1stNum, int2ndNum)

txtResult.Text = intResult.ToString()

End If

End Sub

Private Sub btnSubtract_Click(sender As Object, e As EventArgs) Handles btnSubtract.Click

'Error checking

If (txtFirstNumber.Text Is "" Or txtSecondNumber.Text Is "") Then

MessageBox.Show("Please enter the values")

Else

int1stNum = Integer.Parse(txtFirstNumber.Text)

strSymbol = "-"

int2ndNum = Integer.Parse(txtSecondNumber.Text)

'Calls the class

intResult = mathOps.Subtract(int1stNum, int2ndNum)

txtResult.Text = intResult.ToString()

End If

End Sub

Private Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click

'Error checking

If (txtFirstNumber.Text Is "" Or txtSecondNumber.Text Is "") Then

MessageBox.Show("Please enter the values")

Else

int1stNum = Integer.Parse(txtFirstNumber.Text)

strSymbol = "*"

int2ndNum = Integer.Parse(txtSecondNumber.Text)

'Calls the class

intResult = mathOps.Multiply(int1stNum, int2ndNum)

txtResult.Text = intResult.ToString()

End If

End Sub

Private Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.Click

'Error checking

If (txtFirstNumber.Text Is "" Or txtSecondNumber.Text Is "") Then

MessageBox.Show("Please enter the values")

Else

int1stNum = Integer.Parse(txtFirstNumber.Text)

strSymbol = "/"

int2ndNum = Integer.Parse(txtSecondNumber.Text)

If (int2ndNum = 0) Then

MessageBox.Show("Cannot Divide By Zero")

txtSecondNumber.Clear()

txtSecondNumber.Focus()

Else

'Calls the class

intResult = mathOps.Divide(int1stNum, int2ndNum)

txtResult.Text = intResult.ToString()

End If

End If

End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click

'Clears the form

lstCalculations.Items.Clear()

txtFirstNumber.Clear()

txtSecondNumber.Clear()

txtResult.Clear()

txtFirstNumber.Focus()

End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

Dim strResultant As String

strResultant = int1stNum.ToString & " " & strSymbol & " " & int2ndNum & " = " & intResult.ToString

If (lstCalculations.Items.Count() > 9) Then

MessageBox.Show("Please clear the list to continue")

End If

End Sub

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click

Dim strResultant As String

strResultant = int1stNum.ToString & " " & strSymbol & " " & int2ndNum & " = " & intResult.ToString

lstCalculations.Items.Add(strResultant)

'Clears the form

txtFirstNumber.Clear()

txtSecondNumber.Clear()

txtResult.Clear()

txtFirstNumber.Focus()

End Sub

Private Sub input_validation(sender As Object, e As KeyPressEventArgs) Handles txtFirstNumber.KeyPress, txtSecondNumber.KeyPress

If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then

e.Handled = True

End If

End Sub

End Class

' MathOp class

Public Class MathOp

Public Function Add(ByVal value1 As Integer, ByVal value2 As Integer) As Integer

Return (value1 + value2)

End Function

Public Function Subtract(ByVal value1 As Integer, ByVal value2 As Integer) As Integer

Return (value1 - value2)

End Function

End Class

'MathOp2 class

Public Class MathOp2 : Inherits MathOp

Public Function Multiply(int1stNum As Integer, int2ndNum As Integer) As Integer

Return int1stNum * int2ndNum

End Function

Public Function Divide(int1stNum As Integer, int2ndNum As Integer) As Integer

If int2ndNum > 0 Then

Return int1stNum / int2ndNum

Else

Return -9999

End If

End Function

End Class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

Students also viewed these Databases questions

Question

Distinguish between hyperstress and distress.

Answered: 1 week ago

Question

explain the concept of strategy formulation

Answered: 1 week ago