<%@ Page language="VB" %>
<%@ Register TagPrefix="rntsoft" TagName="Calculator" src="Control.ascx" %>
File: Control.ascx
<%@ Control Inherits="CalculatorControl" src="Control.ascx.vb" %>
Number 1:
Number 2:
OnClick="btOperator_Click" />
OnClick="btOperator_Click"/>
OnClick="btOperator_Click"/>
OnClick="btOperator_Click"/>
The answer is:
File: Control.ascx.vb
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class CalculatorControl : Inherits UserControl
public lblMessage as Label
public btAdd as Button
public btSubtract as Button
public btMultiply as Button
public btDivide as Button
public tbNumber1 as TextBox
public tbNumber2 as TextBox
Sub btOperator_Click(Sender as Object, e as EventArgs)
lblMessage.Text = Operate(CType(Sender, Button).Text, _
tbNumber1.Text, tbNumber2.Text).ToString
End Sub
private function Operate(op as string, number1 as string, number2 as string) as double
select case op
case "+"
Operate = CInt(number1) + CInt(number2)
case "-"
Operate = CInt(number1) - CInt(number2)
case "*"
Operate = CInt(number1) * CInt(number2)
case "/"
Operate = CInt(number1) / CInt(number2)
end select
end function
End Class