hello
I have write the class BinaryArithmeticOperation for making simple arithmetic operations...
I have two operands, a result and an operation...I set an instance of this class by getting
the values from a user interface(html code) but it seems that the object doesn't hold the values, I mean, the object resets...like this:
perform the operation 5+6
press button 5
press button + ( int1 = 5 and operation = "+")
press button 6 ( int1 = 0 and operation = "" ) "here is the problem" int1 reset and operation reset!
press button = ( int2 = 6 )
Can you tell me where is my error?
regards
I have write the class BinaryArithmeticOperation for making simple arithmetic operations...
I have two operands, a result and an operation...I set an instance of this class by getting
the values from a user interface(html code) but it seems that the object doesn't hold the values, I mean, the object resets...like this:
perform the operation 5+6
press button 5
press button + ( int1 = 5 and operation = "+")
press button 6 ( int1 = 0 and operation = "" ) "here is the problem" int1 reset and operation reset!
press button = ( int2 = 6 )
Can you tell me where is my error?
regards
VB.NET:
Public Class BinaryArithmeticOperation
Public int1, int2, result As Integer
Public operation As String
Public Sub doOperation()
Select Case Me.operacion
Case "+"
Me.result = Me.int1 + Me.int2
Case "-"
Me.result = Me.int1 + Me.int2
Case "*"
Me.result = Me.int1 + Me.int2
Case "/"
Me.result = Me.int1 + Me.int2
Case Else
Me.result = -77
End Select
End Sub
End Class
Partial Class _Default
Inherits System.Web.UI.Page
Private op As BinaryArithmeticOperation
Public Sub New()
op = New BinaryArithmeticOperation()
End Sub
Protected Sub number_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles one.Click, two.Click, three.Click, four.Click, five.Click, six.Click, seven.Click, eight.Click, nine.Click, zero.Click
Me.output.Text &= sender.Text
End Sub
Protected Sub operation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles suma.Click, minus.Click, multi.Click, div.Click
op.entero1 = Int32.Parse(output.Text)
op.operacion = sender.Text
output.Text = ""
End Sub
Protected Sub equal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles equal.Click
op.entero2 = Int32.Parse(output.Text)
op.doOperation()
output.Text = (op.resultado).ToString
End Sub
Protected Sub delete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles delete.Click
output.Text = ""
End Sub
End Class
HTML:
<%@ 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>
</div>
<table>
<tr>
<td colspan="4">
<asp:TextBox ID="output" runat="server" Width="352px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="one" runat="server" Text="1" Width="48px" /></td>
<td style="width: 100px"><asp:Button ID="two" runat="server" Text="2" Width="48px" /></td>
<td style="width: 100px"><asp:Button ID="three" runat="server" Text="3" Width="48px" /></td>
<td style="width: 46px"><asp:Button ID="suma" runat="server" Text="+" Width="48px" /></td>
</tr>
<tr>
<td style="width: 100px"><asp:Button ID="four" runat="server" Text="4" Width="48px" /></td>
<td style="width: 100px"><asp:Button ID="five" runat="server" Text="5" Width="48px" /></td>
<td style="width: 100px"><asp:Button ID="six" runat="server" Text="6" Width="48px" /></td>
<td style="width: 46px"><asp:Button ID="minus" runat="server" Text="-" Width="48px" /></td>
</tr>
<tr>
<td style="width: 100px; height: 26px;"><asp:Button ID="seven" runat="server" Text="7" Width="48px" /></td>
<td style="width: 100px; height: 26px;"><asp:Button ID="eight" runat="server" Text="8" Width="48px" /></td>
<td style="width: 100px; height: 26px;"><asp:Button ID="nine" runat="server" Text="9" Width="48px" /></td>
<td style="width: 46px; height: 26px;"><asp:Button ID="multi" runat="server" Text="*" Width="48px" /></td>
</tr>
<tr>
<td style="width: 100px"><asp:Button ID="zero" runat="server" Text="0" Width="48px" /></td>
<td style="width: 100px"><asp:Button ID="delete" runat="server" Text="<-" Width="48px" /></td>
<td style="width: 100px"><asp:Button ID="equal" runat="server" Text="=" Width="48px" /></td>
<td style="width: 46px"><asp:Button ID="div" runat="server" Text="/" Width="48px" /></td>
</tr>
</table>
</form>
</body>
</html>
Last edited: