Friday, April 4, 2008

CREATE A CALCULATOR

%@ Page Language="vB" %>
script language ="vbscript" runat="server">
Dim addone
Dim addtwo
Dim addthree
Dim addfour
Dim addfive
Dim addsix
Dim addseven
Dim addeight
Dim addnine
Public t1
Dim t2
Dim ope
Dim fl1 = "0"
Dim fl2 = "0"
Dim fl3 = "0"
Dim fl4 = "0"
Dim m1, m2, m3, m4
Sub clear(ByVal o As Object, ByVal e As EventArgs)
res.Text = ""
End Sub
Sub click1(ByVal o As Object, ByVal e As EventArgs)
res.Text = one.Text
End Sub
Sub click2(ByVal o As Object, ByVal e As EventArgs)
res.Text = two.Text
End Sub
Sub click3(ByVal o As Object, ByVal e As EventArgs)
res.Text = three.Text
End Sub
Sub click4(ByVal o As Object, ByVal e As EventArgs)
res.Text = four.Text
End Sub
Sub click5(ByVal o As Object, ByVal e As EventArgs)
res.Text = five.Text
End Sub
Sub click6(ByVal o As Object, ByVal e As EventArgs)
res.Text = six.Text
End Sub
Sub click7(ByVal o As Object, ByVal e As EventArgs)
res.Text = seven.Text
End Sub
Sub click8(ByVal o As Object, ByVal e As EventArgs)
res.Text = eight.Text
End Sub
Sub click9(ByVal o As Object, ByVal e As EventArgs)
res.Text = nine.Text
End Sub
Sub addnum(ByVal o As Object, ByVal e As EventArgs)
Session("t1") = res.Text
Session("fl1") = "1"
End Sub
Sub subnum(ByVal o As Object, ByVal e As EventArgs)
Session("t1") = res.Text
Session("fl2") = "1"
End Sub
Sub mulnum(ByVal o As Object, ByVal e As EventArgs)
Session("t1") = res.Text
Session("fl3") = "1"
End Sub
Sub divnum(ByVal o As Object, ByVal e As EventArgs)
Session("t1") = res.Text
Session("fl4") = "1"
End Sub
Sub result(ByVal o As Object, ByVal e As EventArgs)
t2 = res.Text
res.Text = ""
If Session("fl1") = "1" Then
res.Text = Session("t1") + t2
Session("t1") = ""
Session("fl1") = ""
End If
If Session("fl2") = "1" Then
res.Text = Session("t1") - t2
Session("t1") = ""
Session("fl2") = ""
End If
If Session("fl3") = "1" Then
res.Text = Session("t1") * t2
Session("t1") = ""
Session("fl3") = ""
End If
If Session("fl4") = "1" Then
res.Text = Session("t1") / t2
Session("t1") = ""
Session("fl4") = ""
End If
End Sub
/script>
//HTML BODY

body>
form id="frm" runat="server">
table cellpadding="1" cellspacing="1" border="1" width="150" bgcolor="#CCCCCC">
tr>
td colspan="4">
/tr>
tr>
td>
asp:button id="one" text=" 1 " runat="server" onclick="click1">
td>
asp:button id="two" text=" 2 " runat="Server" onclick="click2">
td>
asp:button id="three" text=" 3 " runat="Server" onclick="click3">
td>
asp:button id="add" text=" + " runat="Server" onclick="addnum">
/tr>

td>
asp:button id="four" text=" 4 " runat="server" onclick="click4">
td>
asp:button id="five" text=" 5 " runat="server" onclick="click5">
td>
asp:button id="six" text=" 6 " runat="server" onclick="click6">
td>
asp:button id="sub" text=" - " runat="server" onclick="subnum">
/tr>
tr>
td>
asp:button id="seven" text=" 7 " runat="server" onclick="click7">
td>
asp:button id="eight" text=" 8 " runat="server" onclick="click8">
td>
asp:button id="nine" text=" 9 " runat="Server" onclick="click9">
td>
asp:button id="mul" text=" * " runat="Server" onclick="mulnum">


td>
asp:button id="mem" text="" runat="Server">
td>
asp:button id="cancel" text=" C " runat="Server" onclick="clear">
td>
asp:button id="getrs" text=" = " runat="server" onclick="result">
td>
asp:button id="div" text=" / " runat="Server" onclick="divnum">
/tr>
/table>
/form>
/body>
/html>

No comments: