program to make calculator using command name
-----------------------------------------DESIGN-----------------------------------------------------
-----------------------------------------code---------------------------------------------------------
-----------------------------------------output----------------------------------------------------
-----------------------------------------DESIGN-----------------------------------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" GroupingText="Calculator" Height="242px"
Width="364px">
<asp:Label ID="Label1" runat="server" Text="Enter Number 1"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Enter Number 2"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" CommandName="a" Text="+" Width="62px" />
<asp:Button ID="Button2" runat="server" CommandName="s" Text="-" Width="59px" />
<asp:Button ID="Button3" runat="server" CommandName="m" Text="*" Width="64px" />
<asp:Button ID="Button4" runat="server" CommandName="d" Text="/" Width="62px" />
<br />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Ans is"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</asp:Panel>
</div>
</form>
</body>
</html>
-----------------------------------------code---------------------------------------------------------
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Protected Sub Button1_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs) Handles Button1.Command, Button2.Command, Button3.Command, Button4.Command
Dim x, b As Integer
Dim op As String
op = e.CommandName
x = TextBox1.Text
b = TextBox2.Text
If op = "a" Then
TextBox3.Text = x + b
ElseIf op = "s" Then
TextBox3.Text = x - b
ElseIf op = "m" Then
TextBox3.Text = x * b
ElseIf op = "d" Then
TextBox3.Text = x / b
End If
End Sub
EndClass-----------------------------------------output----------------------------------------------------
codestrew |
No comments:
Post a Comment