Codigo Calculadora

También podría gustarte

Está en la página 1de 5

Public Class calculadora

Dim respaldo As Double


Dim cuenta_puntos As Integer
Dim tipo_operacion As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
respaldo = 0
Me.Hide()
End Sub

Private Sub uno_Click(sender As Object, e As EventArgs) Handles uno.Click


resultado.Text = resultado.Text + "1"
resultado.Select()
resultado.Focus()
End Sub

Private Sub dos_Click(sender As Object, e As EventArgs) Handles dos.Click


resultado.Text = resultado.Text + "2"
resultado.Select()
resultado.Focus()
End Sub

Private Sub resultado_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


resultado.KeyPress

If e.KeyChar = "+" Then

tipo_operacion = 1
cuenta_puntos = 0
respaldo = Val(resultado.Text)
resultado.Text = ""
resultado.Select()
resultado.Focus()

End If

If e.KeyChar = "-" Then

tipo_operacion = 2
cuenta_puntos = 0
respaldo = Val(resultado.Text)
resultado.Text = ""
resultado.Select()
resultado.Focus()

End If
If e.KeyChar = "/" Then

tipo_operacion = 3
cuenta_puntos = 0
respaldo = Val(resultado.Text)
resultado.Text = ""
resultado.Select()
resultado.Focus()

End If
If e.KeyChar = "*" Then
tipo_operacion = 4
cuenta_puntos = 0
respaldo = Val(resultado.Text)
resultado.Text = ""
resultado.Select()
resultado.Focus()

End If

If Asc(e.KeyChar) = 13 Then
Select Case tipo_operacion
Case 1

resultado.Text = respaldo + Val(resultado.Text)

Case 2

resultado.Text = respaldo - Val(resultado.Text)

Case 3

resultado.Text = respaldo / Val(resultado.Text)

Case 4

resultado.Text = respaldo * Val(resultado.Text)

End Select

resultado.Select()
resultado.Focus()
cuenta_puntos = 0

End If

If e.KeyChar = "0" Or e.KeyChar = "1" Or e.KeyChar = "2" Or e.KeyChar = "3" Or


e.KeyChar = "4" Or e.KeyChar = "5" Or e.KeyChar = "6" Or e.KeyChar = "7" Or e.KeyChar =
"8" Or e.KeyChar = "9" Or e.KeyChar = "." Then

If e.KeyChar = "." Then


cuenta_puntos = cuenta_puntos + 1

If cuenta_puntos <= 1 Then

e.Handled = False
Else
e.Handled = True
End If
Else
e.Handled = False

End If
Else
e.Handled = True

End If

End Sub

Private Sub calculadora_Load(sender As Object, e As EventArgs) Handles MyBase.Load


resultado.Select()
resultado.Focus()

End Sub

Private Sub tres_Click(sender As Object, e As EventArgs) Handles tres.Click


resultado.Text = resultado.Text + "3"
resultado.Select()
resultado.Focus()
End Sub

Private Sub cuatro_Click(sender As Object, e As EventArgs) Handles cuatro.Click


resultado.Text = resultado.Text + "4"
resultado.Select()
resultado.Focus()
End Sub

Private Sub cinco_Click(sender As Object, e As EventArgs) Handles cinco.Click


resultado.Text = resultado.Text + "5"
resultado.Select()
resultado.Focus()
End Sub

Private Sub seis_Click(sender As Object, e As EventArgs) Handles seis.Click


resultado.Text = resultado.Text + "6"
resultado.Select()
resultado.Focus()
End Sub

Private Sub siete_Click(sender As Object, e As EventArgs) Handles siete.Click


resultado.Text = resultado.Text + "7"
resultado.Select()
resultado.Focus()
End Sub

Private Sub ocho_Click(sender As Object, e As EventArgs) Handles ocho.Click


resultado.Text = resultado.Text + "8"
resultado.Select()
resultado.Focus()
End Sub

Private Sub nueve_Click(sender As Object, e As EventArgs) Handles nueve.Click


resultado.Text = resultado.Text + "9"
resultado.Select()
resultado.Focus()
End Sub
Private Sub igual_Click(sender As Object, e As EventArgs) Handles igual.Click

Select Case tipo_operacion


Case 1

resultado.Text = respaldo + Val(resultado.Text)

Case 2

resultado.Text = respaldo - Val(resultado.Text)

Case 3

resultado.Text = respaldo / Val(resultado.Text)

Case 4

resultado.Text = respaldo * Val(resultado.Text)

End Select

resultado.Select()
resultado.Focus()
cuenta_puntos = 0

End Sub

Private Sub mas_Click(sender As Object, e As EventArgs) Handles mas.Click

tipo_operacion = 1
cuenta_puntos = 0
respaldo = Val(resultado.Text)
resultado.Text = ""
resultado.Select()
resultado.Focus()
End Sub

Private Sub punto_Click(sender As Object, e As EventArgs) Handles punto.Click

cuenta_puntos = cuenta_puntos + 1

If cuenta_puntos <= 1 Then


resultado.Text = resultado.Text + "."
End If
resultado.Select()
resultado.Focus()
End Sub

Private Sub cero_Click(sender As Object, e As EventArgs) Handles cero.Click


resultado.Text = resultado.Text + "0"
resultado.Select()
resultado.Focus()
End Sub

Private Sub borrar_Click(sender As Object, e As EventArgs) Handles borrar.Click


resultado.Text = ""
cuenta_puntos = 0
respaldo = 0
resultado.Select()
resultado.Focus()
End Sub

Private Sub menos_Click(sender As Object, e As EventArgs) Handles menos.Click


tipo_operacion = 2
cuenta_puntos = 0
respaldo = Val(resultado.Text)
resultado.Text = ""
resultado.Select()
resultado.Focus()
End Sub

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


multiplica.Click
tipo_operacion = 4

respaldo = Val(resultado.Text)
resultado.Text = ""
resultado.Select()
resultado.Focus()
End Sub

Private Sub divide_Click(sender As Object, e As EventArgs) Handles divide.Click


tipo_operacion = 3
cuenta_puntos = 0
respaldo = Val(resultado.Text)
resultado.Text = ""
resultado.Select()
resultado.Focus()
End Sub

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


resultado.TextChanged

End Sub

También podría gustarte