CALCULADORA AULA DE INFORMATICA
Se han hecho matrices de botones agrupados en frames
El codigo es el siguiente:
Dim encendido
As Boolean
Dim pantalla
As String
Dim numero1 As Double
Dim numero2 As Double
Dim resultado
As Double
Dim memoria
As Double
Dim coma As Boolean
Dim operacion
As Integer
Dim k As Integer
Dim s As Integer
Public Sub pulsacion()
Select Case k
'TECLAS NUMERICAS DEL 97 AL 105 DEL BLOQUE NUMERICO Y
DEL 49 AL 57 DEL TECLADO
Case 97:
Command6(11).SetFocus
Command6_Click (0)
Case 98:
Command6(11).SetFocus
Command6_Click (1)
Case 99:
Command6(11).SetFocus
Command6_Click (2)
Case 100:
Command6(11).SetFocus
Command6_Click (3)
Case 101:
Command6(11).SetFocus
Command6_Click (4)
Case 102:
Command6(11).SetFocus
Command6_Click (5)
Case 103:
Command6(11).SetFocus
Command6_Click (6)
Case 104:
Command6_Click (7)
Command6(11).SetFocus
Case 105:
Command6_Click (8)
Command6(11).SetFocus
Case 96:
Command6_Click (10)
Command6(11).SetFocus
Case 110:
Command6_Click (9)
Command6(11).SetFocus
Case 49:
Command6_Click (0)
Command6(11).SetFocus
Case 50:
Command6_Click (1)
Command6(11).SetFocus
Case 51:
Command6_Click (2)
Command6(11).SetFocus
Case 52:
Command6_Click (3)
Command6(11).SetFocus
Case 53:
Command6_Click (4)
Command6(11).SetFocus
Case 54:
Command6_Click (5)
Command6(11).SetFocus
Case 55:
Command6_Click (6)
Command6(11).SetFocus
Case 56:
Command6_Click (7)
Command6(11).SetFocus
Case 57:
Command6_Click (8)
Command6(11).SetFocus
Case 48:
Command6_Click (10)
Command6(11).SetFocus
'TECLAS DE OPERACIONES
Case 107:
Command7_Click (0)
Command7(0).SetFocus
Case 109:
Command7_Click (1)
Command7(1).SetFocus
Case 106:
Command7_Click (2)
Command7(2).SetFocus
Case 111:
Command7_Click (3)
Command7(3).SetFocus
Case 110:
Command6_Click (9)
Command6(9).SetFocus
'TECLA INTRO, IGUAL
Case 13:
Command6_Click (11)
Command6(11).SetFocus
End Select
End Sub
Private Sub
Command1_Click(Index As Integer)
Select Case Index
Case 0:
pantalla =
"0"
Label1.Caption
= pantalla
coma = False
Case 1:
If encendido Then
encendido =
False
Label1.Caption = ""
Shape1.BackColor = vbRed
Command1(1).Caption =
"&ON"
Else
encendido =
True
Label1.Caption
= "0"
numero1
= 0
numero2
= 0
resultado = 0
coma = False
operacion = 0
pantalla
= ""
introducirnumero = True
Shape1.BackColor = vbGreen
Command1(1).Caption =
"&OFF"
End If
End Select
End Sub
Private Sub
Command1_KeyDown(Index As Integer, KeyCode As
Integer, Shift As Integer)
If encendido
Then
k = KeyCode
s = Shift
pulsacion
End If
End Sub
Private Sub Command2_Click()
If encendido
Then
Dim longitud
As Integer
longitud = Len(Label1.Caption)
lontitud = longitud - 1
If longitud
<= 1 Then
Label1.Caption = "0"
Else
Label1.Caption =
Left(Label1.Caption, lontitud)
End If
pantalla = Label1.Caption
End If
End Sub
Private Sub Command2_KeyDown(KeyCode As Integer, Shift As Integer)
If encendido
Then
k = KeyCode
s = Shift
pulsacion
End If
End Sub
Private Sub
Command3_Click(Index As Integer)
If encendido
Then
Select Case Index
Case 0:
memoria = CDbl(Label1.Caption)
Case 1:
memoria = memoria + CDbl(Label1.Caption)
Case 2:
Label1.Caption = Format(memoria,
"0.#############")
End Select
pantalla = ""
End If
End Sub
Private Sub
Command3_KeyDown(Index As Integer, KeyCode As
Integer, Shift As Integer)
If encendido
Then
k = KeyCode
s = Shift
pulsacion
End If
End Sub
Private Sub
Command6_Click(Index As Integer)
If encendido
Then
Select Case Index
Case 0:
If pantalla =
"0" Then
pantalla
= "1"
Else
pantalla
= pantalla + "1"
End If
Case 1:
If pantalla =
"0" Then
pantalla = "2"
Else
pantalla = pantalla + "2"
End If
Case 2:
If pantalla
= "0" Then
pantalla
= "3"
Else
pantalla
= pantalla + "3"
End If
Case 3:
If pantalla
= "0" Then
pantalla
= "4"
Else
pantalla
= pantalla + "4"
End If
Case 4:
If pantalla
= "0" Then
pantalla
= "5"
Else
pantalla
= pantalla + "5"
End If
Case 5:
If pantalla
= "0" Then
pantalla
= "6"
Else
pantalla
= pantalla + "6"
End If
Case 6:
If pantalla
= "0" Then
pantalla
= "7"
Else
pantalla
= pantalla + "7"
End If
Case 7:
If pantalla
= "0" Then
pantalla
= "8"
Else
pantalla
= pantalla + "8"
End If
Case 8:
If pantalla
= "0" Then
pantalla
= "9"
Else
pantalla
= pantalla + "9"
End If
Case 10:
If pantalla
= "0" Then
pantalla
= "0"
Else
pantalla
= pantalla + "0"
End If
Case 9:
If Not coma Then
If pantalla =
"" Then pantalla = "0"
pantalla = pantalla + ","
coma = True
End If
Case 11:
funcionigual
End Select
If Index <> 11 Then Label1.Caption
= pantalla
End If
End Sub
Private Sub funcionigual()
numero2 = CDbl(Label1.Caption)
Select Case operacion
Case 0:
resultado = numero1 + numero2
Case 1:
resultado =
numero1 - numero2
Case 2:
resultado =
numero1 * numero2
Case 3:
If numero2 <> 0 Then
resultado = numero1 / numero2
Case 4:
resultado =
numero1 / 100 * numero2
End Select
If operacion = 3
And numero2 = 0 Then
pantalla = "Error divisor cero"
Else
pantalla = Format(resultado,
"0.#############")
End If
Label1.Caption = pantalla
pantalla = ""
End Sub
Private Sub
Command6_KeyDown(Index As Integer, KeyCode As
Integer, Shift As Integer)
If encendido
Then
k = KeyCode
s = Shift
pulsacion
End If
End Sub
Private Sub
Command7_Click(Index As Integer)
Command7(Index).SetFocus
If encendido
Then
numero1 = CDbl(Label1.Caption)
Select Case Index
Case 5:
numero1 = Sqr(numero1)
Case 6:
numero1 = numero1 * numero1
Case 7:
numero1 = Sin((numero1 / 180 * 3.141592654))
Case 8:
numero1 = Cos((numero1 / 180 * 3.141592654))
Case 9:
numero1 = Tan((numero1 / 180 * 3.141592654))
End Select
coma = False
operacion = Index
pantalla = ""
Label1.Caption =
Format(numero1, "0.#############")
End If
End Sub
Private Sub
Command7_KeyDown(Index As Integer, KeyCode As
Integer, Shift As Integer)
k = KeyCode
s = Shift
pulsacion
End Sub
Private Sub Form_Load()
encendido = True
memoria = 0
numero1 = 0
numero2 = 0
resultado = 0
coma = False
operacion = 0
introducirnumero = True
pantalla = ""
End Sub
Private Sub
mnucolorfondo_Click()
CommonDialog1.ShowColor
Form1.BackColor =
CommonDialog1.Color
Frame1.BackColor =
CommonDialog1.Color
Frame2.BackColor =
CommonDialog1.Color
Frame3.BackColor =
CommonDialog1.Color
Frame4.BackColor =
CommonDialog1.Color
End Sub
Private Sub
mnucolorfuente_Click()
CommonDialog1.ShowColor
Label1.ForeColor =
CommonDialog1.Color
End Sub
Private Sub
mnucolorpantalla_Click()
CommonDialog1.ShowColor
Label1.BackColor =
CommonDialog1.Color
End Sub
Private Sub mnusalir_Click()
End
End Sub