<%@ Page language="VB" %>
<%@ Register TagPrefix="java2s" TagName="Calculator" src="Control.ascx" %>
<html><body>
<form runat="server">
<java2s:Calculator id="Calc1" runat="server"/>
</form>
</body></html>
File: Control.ascx
<%@ Control Inherits="CalculatorControl" src="Control.ascx.vb" %>
Number 1: <asp:textbox id="tbNumber1" runat="server"/><br>
Number 2: <asp:textbox id="tbNumber2" runat="server"/>
<asp:button id="btAdd" runat="server" Text="+"
OnClick="btOperator_Click" />
<asp:button id="btSubtract" runat="server" Text="-"
OnClick="btOperator_Click"/>
<asp:button id="btMultiply" runat="server" Text="*"
OnClick="btOperator_Click"/>
<asp:button id="btDivide" runat="server" Text="/"
OnClick="btOperator_Click"/>
The answer is:
<asp:label id="lblMessage" runat="server"/>
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
|