Sei sulla pagina 1di 4

Ó

OBJETO TEXT NAME


TextBox Pantalla
Button 0 num0
Button 1 num1
Button 2 num2
Button 3 num3
Button 4 num4
Button 5 num5
Button 6 num6
Button 7 num7
Button 8 num8
Button 9 num9
Button . ButtonPunto
Button * BtnMultiplicar
Button + BtnSumar
Button - BtnRestar
Button / BtnDividir
Button C BtnBorrar
El formulario guardarlo como FrmCalculadora

Declarar las siguientes variables:


Public Class FrmCalculadora
Dim Secuencia As Boolean = True
Dim Punto As Boolean
Dim operacion, borrado As String
Dim numero1, numero2, resultado As Double

Programar en cada uno de los Buttons (0,1,2,3,4,5,6,7,8,9,.,-,+,*,/,=,C)

Private Sub num1_Click(sender As Object, e As EventArgs) Handles num1.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "1"
Secuencia = False
Punto = True
Else
Pantalla.Text = Pantalla.Text + "1"
End If
End Sub

Private Sub num2_Click(sender As Object, e As EventArgs) Handles num2.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "2"
Secuencia = False
Punto = True

Página 1 de 4
Else
Pantalla.Text = Pantalla.Text + "2"
End If
End Sub

Private Sub num3_Click(sender As Object, e As EventArgs) Handles num3.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "3"
Secuencia = False
Punto = True
Else
Pantalla.Text = Pantalla.Text + "3"
End If
End Sub

Private Sub num4_Click(sender As Object, e As EventArgs) Handles num4.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "4"
Secuencia = False
Punto = True
Else
Pantalla.Text = Pantalla.Text + "4"
End If
End Sub

Private Sub num5_Click(sender As Object, e As EventArgs) Handles num5.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "5"
Secuencia = False
Punto = True
Else
Pantalla.Text = Pantalla.Text + "5"
End If
End Sub

Private Sub num6_Click(sender As Object, e As EventArgs) Handles num6.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "6"
Secuencia = False
Punto = True
Else
Pantalla.Text = Pantalla.Text + "6"
End If
End Sub

Private Sub num7_Click(sender As Object, e As EventArgs) Handles num7.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "7"
Secuencia = False
Punto = True
Else
Pantalla.Text = Pantalla.Text + "7"
End If

Página 2 de 4
End Sub

Private Sub num8_Click(sender As Object, e As EventArgs) Handles num8.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "8"
Secuencia = False
Punto = True
Else
Pantalla.Text = Pantalla.Text + "8"
End If
End Sub

Private Sub num9_Click(sender As Object, e As EventArgs) Handles num9.Click


If Secuencia = True Then
Pantalla.Text = ""
Pantalla.Text = "9"
Secuencia = False
Punto = True
Else
Pantalla.Text = Pantalla.Text + "9"
End If
End Sub

Private Sub num0_Click(sender As Object, e As EventArgs) Handles num0.Click


If (Pantalla.Text = 0) Then
Return

Else
If Secuencia = True Then
Pantalla.Text = "0"
Punto = True

else
Pantalla.Text = Pantalla.Text + "0"
End If
End If

End Sub

Private Sub BtnSumar_Click(sender As Object, e As EventArgs) Handles BtnSumar.Click


operacion = "+"
numero1 = Double.Parse(Pantalla.Text)
Secuencia = True
End Sub

Private Sub BtnRestar_Click(sender As Object, e As EventArgs) Handles BtnRestar.Click


operacion = "-"
numero1 = Double.Parse(Pantalla.Text)
Secuencia = True
End Sub

Private Sub BtnDividir_Click(sender As Object, e As EventArgs) Handles BtnDividir.Click


operacion = "/"
numero1 = Double.Parse(Pantalla.Text)
Secuencia = True
End Sub

Página 3 de 4
Private Sub BtnMultiplicar_Click(sender As Object, e As EventArgs) Handles BtnMultiplicar.Click
operacion = "*"
numero1 = Double.Parse(Pantalla.Text)
Secuencia = True
End Sub

Private Sub BtnIgual_Click(sender As Object, e As EventArgs) Handles BtnIgual.Click


numero2 = Double.Parse(Pantalla.Text)
If operacion = "+" Then
resultado = numero1 + numero2
Pantalla.Text = resultado.ToString()
Secuencia = True
End If
If operacion = "-" Then
resultado = numero1 - numero2
Pantalla.Text = resultado.ToString()
Secuencia = True
End If
If operacion = "*" Then
resultado = numero1 * numero2
Pantalla.Text = resultado.ToString()
Secuencia = True
End If
If operacion = "/" Then
resultado = numero1 / numero2
Pantalla.Text = resultado.ToString()
Secuencia = True

End If
End Sub

Private Sub BtnBorrar_Click(sender As Object, e As EventArgs) Handles BtnBorrar.Click


Pantalla.Text = "0"
numero1 = 0
numero2 = 0
Secuencia = True
End Sub

Private Sub ButtonPunto_Click(sender As Object, e As EventArgs) Handles ButtonPunto.Click


If Punto = True Then
Pantalla.Text = Pantalla.Text + ","
Punto = False
Else
Return
End If
Secuencia = False
End Sub
End Class

Página 4 de 4

Potrebbero piacerti anche