CALCULADORA FELIPE EN VISUAL BASIC. NET
Creamos una aplicación para windows e
introducimos los controles siguientes en el control formulario.
Una vez introducidos y clickando en cada uno de
los botones procederemos a introducir el siguiente código.
Public Class Form1
Dim
encendido As Boolean
Dim
operacion As Integer
Dim
numero1 As Double
Dim
numero2 As Double
Dim
resultado As Double
Dim
memoria As Double
Dim
coma As Boolean
Dim
pantalla As String
Private
Sub TextBox1_TextChanged(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
End
Sub
Private
Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load, MyBase.Load,
MyBase.Load
'Defino las variables que vamos a
utilizar
encendido = True
coma
= False
numero1 = 0
numero2 = 0
memoria = 0
pantalla = "0"
TextBox1.Text =
pantalla
End Sub
Private
Sub Button17_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button17.Click
'Boton de encendido y apagado
If encendido Then
pantalla = ""
encendido = False
Else
encendido = True
coma = False
numero1 = 0
numero2 = 0
memoria = 0
pantalla = "0"
End If
TextBox1.Text = pantalla
End
Sub
Private
Sub Button10_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
'boton 1
If encendido Then
If pantalla = 0 Then
pantalla = "1"
Else
pantalla = pantalla + "1"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button11_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button11.Click
'boton 2
If encendido Then
If pantalla = 0 Then
pantalla = "2"
Else
pantalla = pantalla + "2"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button12_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button12.Click
'boton 3
If encendido Then
If pantalla = 0 Then
pantalla = "3"
Else
pantalla = pantalla + "3"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button7_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
'boton 4
If encendido Then
If pantalla = 0 Then
pantalla = "4"
Else
pantalla = pantalla + "4"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button8_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
'boton 5
If encendido Then
If pantalla = 0 Then
pantalla = "5"
Else
pantalla = pantalla + "5"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button9_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
'boton 6
If encendido Then
If pantalla = 0 Then
pantalla = "6"
Else
pantalla = pantalla + "6"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
'boton 7
If encendido Then
If pantalla = 0 Then
pantalla = "7"
Else
pantalla = pantalla + "7"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs)
'boton 8
If encendido Then
If pantalla = 0 Then
pantalla = "8"
Else
pantalla = pantalla + "8"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
'boton 9
If encendido Then
If pantalla = 0 Then
pantalla = "9"
Else
pantalla = pantalla + "9"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button13_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click
'boton coma
If encendido Then
If coma = False
Then
pantalla = pantalla + "."
coma = True
Else
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button26_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button26.Click
' boton salir
End
End
Sub
Private
Sub Button14_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button14.Click
'boton 0
If encendido Then
If pantalla = 0 Then
pantalla = "0"
Else
pantalla = pantalla + "0"
End If
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button24_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button24.Click
'boton suma
If encendido Then
operacion = 1
numero1 = Double.Parse(pantalla)
pantalla = 0
coma = False
TextBox2.Text = "+"
End If
End
Sub
Private
Sub Button25_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button25.Click
'boton resta
If encendido Then
operacion = 2
numero1 = Double.Parse(pantalla)
pantalla = 0
coma = False
TextBox2.Text = "-"
End If
End
Sub
Private
Sub Button22_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button22.Click
'boton producto
If encendido Then
operacion = 3
numero1 = Double.Parse(pantalla)
pantalla = 0
coma = False
TextBox2.Text = "*"
End If
End
Sub
Private
Sub Button23_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button23.Click
'boton division
If encendido Then
operacion = 4
numero1 = Double.Parse(pantalla)
pantalla = 0
coma = False
TextBox2.Text = "/"
End If
End
Sub
Private
Sub Button20_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button20.Click
'boton cuadrado
If encendido Then
operacion = 5
numero1 = Double.Parse(pantalla) * Double.Parse(pantalla)
pantalla = 0
coma = False
TextBox2.Text = "x2"
End If
End
Sub
Private
Sub Button21_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button21.Click
'boton raiz
If encendido Then
operacion = 6
numero1 = Math.Sqrt(Double.Parse(pantalla))
pantalla = 0
coma = False
TextBox2.Text = "raiz"
End If
End
Sub
Private
Sub Button18_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button18.Click
'boton seno
If encendido Then
operacion = 7
numero1 = Math.Sin(Math.PI / 180 * Double.Parse(pantalla))
pantalla = 0
coma = False
TextBox2.Text = "seno"
End If
End
Sub
Private
Sub Button19_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs)
'boton tan
If encendido Then
operacion = 1
numero1 = Math.Tan(Math.PI / 180 * Double.Parse(pantalla))
pantalla = 0
coma = False
TextBox2.Text = "tan"
End If
End
Sub
Private
Sub Button16_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button16.Click
'boton clear
If encendido Then
pantalla = "0"
TextBox1.Text = pantalla
End If
End
Sub
Private
Sub Button15_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button15.Click
' boton igual
If encendido Then
numero2 = Double.Parse(pantalla)
pantalla = 0
coma = False
Select Case
operacion
Case 1
resultado = numero1 +
numero2
Case 2
resultado = numero1 - numero2
Case 3
resultado = numero1 * numero2
Case 4
resultado = numero1 / numero2
End Select
pantalla = resultado.ToString()
TextBox2.Text = ""
TextBox1.Text = pantalla
End If
End Sub
End Class