Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Me.btnAdd.Click, AddressOf Calculate
AddHandler Me.btnSubtract.Click, AddressOf Calculate
AddHandler Me.btnMultiply.Click, AddressOf Calculate
AddHandler Me.btnDivide.Click, AddressOf Calculate
End Sub
Public Sub Calculate(ByVal sender As Object, ByVal e As System.EventArgs)
Dim op1 As Integer = CType(Me.TextBox1.Text, Integer)
Dim op2 As Integer = CType(Me.TextBox2.Text, Integer)
Dim result As Integer
Select Case CType(sender, button).CommandName
Case "Add "
result = op1 + op2
Case "Subtract "
result = op1 - op2
Case "Multiply "
result = op1 * op2
Case "Divide "
' Divide two numbers and return an integer result.
If op2 > 0 Then
result = op1 \ op2
Else
result = 0
End If
Case Else
' Error handling code here.