<%
''' Class Calculadora
''' <author>Paulo Martins</author>
Class Calculadora
Private x_
Private y_
'-- Private Sub Class_Initialize()
' x_ = 6
' y_ = 3
'-- End Sub
Private Sub Class_Terminate()
End Sub
Public Sub Calculadora(x_, y_)
x = x_
y = y_
End Sub
Public Property Get x()
x=x_
End Property
Public Property Let x(value)
x_=value
End Property
Public Property Get y()
y=y_
End Property
Public Property Let y(value)
y_=value
End Property
Public Function Soma()
Soma = me.x + me.y
Response.Write ("A Soma de X e Y: " & Soma)
Response.Write ("<br>")
End Function
Public Function subtracao()
subtracao = me.x - me.y
Response.Write ("A Subtração de X e Y: " & subtracao)
Response.Write ("<br>")
End Function
Public Function ToString()
ToString = "<br>O Valor de X vale: " & me.x & "<br>O Valor de Y vale: " & me.y
Response.Write ToString
End Function
End class
'-- class Principal
'-- dim obj
'-- Set obj = new Calculadora
'-- obj.Calculadora 7, 3
'-- obj.x = 8
'-- obj.y = 4
'-- obj.subtracao() 'Chamando a função soma.
'-- obj.soma()
'-- obj.ToString()
'-- set obj = nothing
%>
Pagina PRINCIPAL: indexCalculadora.asp
<!-- #include file ="class2Calculadora.asp" -->
<!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>
<title></title>
</head>
<body>
<form method="post" action="">
<label>Calculadora</label>
Digite o Primeiro Valor: <input type="text" id="x" name="x" /><br />
Digite o Segundo Valor <input type="text" id="y" name="y" /><br />
<input type="submit" value="Soma" id="btnSoma" name="btnSoma" />
</form>
</body>
</html>
<%
'-- class Principal
'For Each dados in Request.Form
' vetDados(I) = Request.Form(dados)
' I = I + 1
'Next
dim obj
Set obj = new Calculadora
'--obj.Calculadora 7, 3
obj.Calculadora Request.Form("x"), Request.Form("y")
'-- obj.subtracao() 'Chamando a função soma.
obj.soma()
obj.ToString()
set obj = nothing
%>
Pergunta
Martinsrj
Olá pessoal, boa tarde!
Possuo um classe de calculadora, porem não soma.
Aparece o seguinte resultado:
A Soma de X e Y: 105
O Valor de X vale: 10
O Valor de Y vale: 5
class2Calculadora.asp
<% ''' Class Calculadora ''' <author>Paulo Martins</author> Class Calculadora Private x_ Private y_ '-- Private Sub Class_Initialize() ' x_ = 6 ' y_ = 3 '-- End Sub Private Sub Class_Terminate() End Sub Public Sub Calculadora(x_, y_) x = x_ y = y_ End Sub Public Property Get x() x=x_ End Property Public Property Let x(value) x_=value End Property Public Property Get y() y=y_ End Property Public Property Let y(value) y_=value End Property Public Function Soma() Soma = me.x + me.y Response.Write ("A Soma de X e Y: " & Soma) Response.Write ("<br>") End Function Public Function subtracao() subtracao = me.x - me.y Response.Write ("A Subtração de X e Y: " & subtracao) Response.Write ("<br>") End Function Public Function ToString() ToString = "<br>O Valor de X vale: " & me.x & "<br>O Valor de Y vale: " & me.y Response.Write ToString End Function End class '-- class Principal '-- dim obj '-- Set obj = new Calculadora '-- obj.Calculadora 7, 3 '-- obj.x = 8 '-- obj.y = 4 '-- obj.subtracao() 'Chamando a função soma. '-- obj.soma() '-- obj.ToString() '-- set obj = nothing %>Pagina PRINCIPAL: indexCalculadora.asp<!-- #include file ="class2Calculadora.asp" --> <!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> <title></title> </head> <body> <form method="post" action=""> <label>Calculadora</label> Digite o Primeiro Valor: <input type="text" id="x" name="x" /><br /> Digite o Segundo Valor <input type="text" id="y" name="y" /><br /> <input type="submit" value="Soma" id="btnSoma" name="btnSoma" /> </form> </body> </html> <% '-- class Principal 'For Each dados in Request.Form ' vetDados(I) = Request.Form(dados) ' I = I + 1 'Next dim obj Set obj = new Calculadora '--obj.Calculadora 7, 3 obj.Calculadora Request.Form("x"), Request.Form("y") '-- obj.subtracao() 'Chamando a função soma. obj.soma() obj.ToString() set obj = nothing %>Link para o comentário
Compartilhar em outros sites
3 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.