Public Class frmCalculate

  'Create both machines
  Dim adder As New AddingMachine()
  Dim calc As New Calculator()

  Private Sub radAddingMachine_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radAddingMachine.CheckedChanged
    'Hide the multiply and divide functionality.
    btnMultiply.Visible = False
    btnDivide.Visible = False
  End Sub

  Private Sub radCalculator_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radCalculator.CheckedChanged
    'Show the multiply and divide functionality.
    btnMultiply.Visible = True
    btnDivide.Visible = True
  End Sub

  Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    'Add two numbers
    If radAddingMachine.Checked Then
      'If adding machine selected, use it to get the result
      adder.FirstNumber = CDbl(txtNumber1.Text)
      adder.SecondNumber = CDbl(txtNumber2.Text)
      txtResult.Text = CStr(adder.Add)
    Else
      'If calculator selected, use it to get the result.
      calc.FirstNumber = CDbl(txtNumber1.Text)
      calc.SecondNumber = CDbl(txtNumber2.Text)
      txtResult.Text = CStr(calc.Add)
    End If
  End Sub

  Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
    'Subtract two numbers
    If radAddingMachine.Checked Then
      'If adding machine selected, use it to get the result.
      adder.FirstNumber = CDbl(txtNumber1.Text)
      adder.SecondNumber = CDbl(txtNumber2.Text)
      txtResult.Text = CStr(adder.Subtract)
    Else
      'If calculator selected, use it to get the result.
      calc.FirstNumber = CDbl(txtNumber1.Text)
      calc.SecondNumber = CDbl(txtNumber2.Text)
      txtResult.Text = CStr(calc.Subtract)
    End If
  End Sub

  Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click
    'Multiply two numbers
    calc.FirstNumber = CDbl(txtNumber1.Text)
    calc.SecondNumber = CDbl(txtNumber2.Text)
    txtResult.Text = CStr(calc.Multiply)
  End Sub

  Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click
    'Divide two numbers
    calc.FirstNumber = CDbl(txtNumber1.Text)
    calc.SecondNumber = CDbl(txtNumber2.Text)
    txtResult.Text = CStr(calc.Divide)
  End Sub
End Class     'frmCalculate

Class AddingMachine
  'Private m_num1, m_num2 As Double

  Public Property FirstNumber() As Double
  '  Get
  '    Return m_num1
  '  End Get
  '  Set(ByVal value As Double)
  '    m_num1 = value
  '  End Set
  'End Property

  Public Property SecondNumber() As Double
  '  Get
  '    Return m_num2
  '  End Get
  '  Set(ByVal value As Double)
  '    m_num2 = value
  '  End Set
  'End Property

  Function Add() As Double
    Return FirstNumber + SecondNumber
  End Function

  Function Subtract() As Double
    Return FirstNumber - SecondNumber
  End Function
End Class     'AddingMachine

Class Calculator
  Inherits AddingMachine
  'Calculator inherits properties FirstNumber and SecondNumber
  'and functions add() and subtract().

  Function Multiply() As Double
    Return FirstNumber * SecondNumber
  End Function

  Function Divide() As Double
    Return FirstNumber / SecondNumber
  End Function
End Class     'Calculator
