Public Class calculate 'declare a private variable as a double Private _num1 As Double Private _num2 As Double Private _total As Double 'set a readonly property for the total of the MDAS ReadOnly Property total() As Double Get Return _total 'return the total End Get End Property 'create a property for a private variable so that you can access it Property num1() As Double Get Return _num1 'return the first value End Get Set(ByVal value As Double) _num1 = value 'set the first value End Set End Property Property num2() As Double Get Return _num2 End Get Set(ByVal value As Double) _num2 = value End Set End Property 'create the sub procedures of the MDAS Public Sub multiply() 'formula of multiplication _total = num1 * num2 End Sub Public Sub divide() 'formula of division _total = num1 / num2 End Sub Public Sub add() 'formula of addition _total = num1 + num2 End Sub Public Sub subtract() 'formula of subtraction _total = num1 - num2 End Sub End Class
Public Class Form1 'create a sub procedure for the events of clicking the radio button that handles all of it. Private Sub RadioButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Radio_Subtaction.Click, Radio_Multiplication.Click, Radio_Division.Click, Radio_Addition.Click 'call a constructor method and return to cal as an instance of a class Dim cal As calculate = New calculate() 'declaring the string variable represent as a textbox Dim txtnum1 As String = TextBox1.Text Dim txtnum2 As String = TextBox2.Text 'declaring the double variable Dim dbl_val1 As Double Dim dbl_val2 As Double 'convert the string to double dbl_val1 = Double.Parse(txtnum1) dbl_val2 = Double.Parse(txtnum2) 'get the value of the converted variable 'to pass it into the variable in the class cal.num1 = dbl_val1 cal.num2 = dbl_val2 'the condition is, if the radiobutton is clicked, 'the operation of MDAS executes. If Radio_Multiplication.Checked Then 'result: cal.multiply() 'call a subname in a class for multiplying ElseIf Radio_Division.Checked Then 'result: cal.divide() 'call a subname in a class for dividing ElseIf Radio_Addition.Checked Then 'result: cal.add() 'call a subname in a class for adding ElseIf Radio_Subtaction.Checked Then 'result: cal.subtract() 'call a subname in a class for subtracting End If Else 'the result is: 'if the textbox is empty or has a string value TextBox3.Text = "Enter a number" Return End If 'put the result of the MDAS to a textbox. TextBox3.Text = cal.total() End Sub End Class