0% found this document useful (0 votes)
15 views3 pages

Public Class Form1

This document contains the code for a basic calculator application. It defines classes and methods for handling button clicks on the calculator interface and performing arithmetic operations. When number or operator buttons are clicked, it concatenates the values to a text field. When the equals button is clicked, it evaluates the operation using the stored values and operators. It also contains methods for clearing values and restricting input to the valid calculator interactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Public Class Form1

This document contains the code for a basic calculator application. It defines classes and methods for handling button clicks on the calculator interface and performing arithmetic operations. When number or operator buttons are clicked, it concatenates the values to a text field. When the equals button is clicked, it evaluates the operation using the stored values and operators. It also contains methods for clearing values and restricting input to the valid calculator interactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Public Class Form1

Dim Operacion As String


Dim ValorRESULTADO As Nullable(Of Double) = Nothing
Dim Valor2 As Nullable(Of Double) = Nothing
Dim SePrecionaOperador As Boolean
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "1"
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "2"
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "3"
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles


Button4.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "4"
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles


Button5.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "5"
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles


Button6.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "6"
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles


Button7.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "7"
End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles


Button8.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "8"
End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles


Button9.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "9"
End Sub
Private Sub Button0_Click(sender As Object, e As EventArgs) Handles
Button0.Click
EvaluaRestriccionesParaConcatenar()
TXTRESULTADO.Text &= "0"
End Sub

Private Sub Buttonpunto_Click(sender As Object, e As EventArgs) Handles


Buttonpunto.Click
EvaluaRestriccionesParaConcatenar()
If InStr(TXTRESULTADO.Text, ".", CompareMethod.Text) = 0 Then
TXTRESULTADO.Text &= "."
End If
End Sub

Private Sub Buttonsuma_Click(sender As Object, e As EventArgs) Handles


Buttonsuma.Click
EvaluayHazOperacion()
Operacion = "+"
End Sub

Private Sub Buttonresta_Click(sender As Object, e As EventArgs) Handles


Buttonresta.Click
EvaluayHazOperacion()
Operacion = "-"
End Sub

Private Sub Buttonmultiplicacion_Click(sender As Object, e As EventArgs) Handles


Buttonmultiplicacion.Click
EvaluayHazOperacion()
Operacion = "*"
End Sub

Private Sub Buttondivicion_Click(sender As Object, e As EventArgs) Handles


Buttondivicion.Click
EvaluayHazOperacion()
Operacion = "/"
End Sub

Private Sub Buttonigual_Click(sender As Object, e As EventArgs) Handles


Buttonigual.Click
EvaluayHazOperacion()
Operacion = ""
End Sub

Private Sub Buttonborrar_Click(sender As Object, e As EventArgs) Handles


Buttonborrar.Click
TXTRESULTADO.Text = "0"
Valor2 = Nothing
ValorRESULTADO = Nothing
End Sub
Public Sub EvaluayHazOperacion()
SePrecionaOperador = True
Valor2 = Val(TXTRESULTADO.Text)
If ValorRESULTADO IsNot Nothing Then
Select Case Operacion
Case "+"
ValorRESULTADO = ValorRESULTADO + Valor2
Case "-"
ValorRESULTADO -= Valor2
Case "*"
ValorRESULTADO *= Valor2
Case "/"
ValorRESULTADO /= Valor2

End Select
TXTRESULTADO.Text = ValorRESULTADO
Else
ValorRESULTADO = Valor2

End If
End Sub
Public Sub EvaluaRestriccionesParaConcatenar()
If SePrecionaOperador = True Then
TXTRESULTADO.Text = ""
SePrecionaOperador = False
ElseIf TXTRESULTADO.Text = 0 Then
TXTRESULTADO.Text = ""
End If
End Sub
End Class

You might also like