Codigo de una calculadora

Bueno espero que me puedan ayudar quiero que si pueden facilitar un codigo para una calculadora en visual basic gracias por su cooperacion

1 Respuesta

Respuesta
1
'command1(1).tag Guarda el primer numero
'command1(2).tag Guarda el segundo numero
'command2(2).tag detecta borrado de pantalla
'command2(3).tag 1= primera operacion,
' 2= segunda operacion (resultado)
' 3= reinicio
'command2(4).tag Contiene operación 1 suma, 2 resta, 3 div y 4 multip
'command2(5).tag contiene la memoria
'command2(6).tag
Private Sub Form_Load()
Command2(2).Tag = 0
Command2(3).Tag = 1
Command2(4).Tag = 0
Label1.Caption = 0
End Sub
Private Sub Command1_Click(index As Integer)
If Command2(2).Tag = 1 Then 'borrado de pantalla
Command2(2).Tag = 0
End If
If Label1.Caption <> "0" Then
If Command2(3).Tag = 3 Then
Label1.Caption = ""
Command2(3).Tag = 4
End If
Label1.Caption = Label1.Caption & index
Else 'es cero
Label1.Caption = ""
Label1.Caption = Label1.Caption & index
End If
End Sub
Private Sub Command2_Click(index As Integer)
On Error GoTo fallo
If index = 5 Then
Command2(6).Tag = Command2(4).Tag
End If
Command2(4).Tag = index
Cmdcoma.Enabled = True
Select Case index
Case 1, 2, 3, 4 'suma, resta, division y multiplicacion
Select Case Command2(3).Tag
Case 1
Command1(1).Tag = CDbl(Label1.Caption)
Command2(1).Enabled = False
Command2(2).Enabled = False
Command2(3).Enabled = False
Command2(4).Enabled = False
Command2(index).Enabled = True
Label1.Caption = ""
Command2(3).Tag = 2
Case Else
If Label1.Caption <> "" Then
Command1(2).Tag = CDbl(Label1.Caption)
Select Case Command2(4).Tag
Case 1
Label1.Caption = CDbl(Command1(1).Tag) + CDbl(Command1(2).Tag)
Case 2
Label1.Caption = CDbl(Command1(1).Tag) - CDbl(Command1(2).Tag)
Case 3
Label1.Caption = CDbl(Command1(1).Tag) * CDbl(Command1(2).Tag)
Case 4
Label1.Caption = CDbl(Command1(1).Tag) / CDbl(Command1(2).Tag)
End Select
Command1(1).Tag = Label1.Caption
Command2(3).Tag = 3
End If
End Select
Case 5 'memoria
If Label1.Caption <> "" Then
Command2(5).Tag = CDbl(Label1.Caption)
Lblmemo.Caption = "Memoria = " & CDbl(Label1.Caption)
Else
Label1.Caption = CDbl(Command2(5).Tag)
Command2(3).Tag = 5
End If
Case 6 'AC, borrado completo
Command1(1).Tag = 0
Command1(2).Tag = 0
Label1.Caption = 0
Cmdcoma.Enabled = True
Command2(1).Enabled = True
Command2(2).Enabled = True
Command2(3).Enabled = True
Command2(4).Enabled = True
Case 7 'C, borrado de pantalla
Label1.Caption = 0
Cmdcoma.Enabled = True
Case 8 'CM, borrado de memoria
Command2(5).Tag = 0
Lblmemo.Caption = "Sin Memoria"
Case 9 '+/-
Label1.Caption = Label1.Caption * -1
End Select
fallo:
Select Case Err.Number
Case 11
MsgBox " no se puede dividir por 0 "
Case 6
MsgBox " numero demasiado grande "
Command1(1).Tag = 0
Command1(2).Tag = 0
Label1.Caption = 0
Cmdcoma.Enabled = True
Command2(1).Enabled = True
Command2(2).Enabled = True
Command2(3).Enabled = True
Command2(4).Enabled = True
End Select
Cmdigual.Tag = 0
End Sub
Private Sub Cmdigual_Click()
Cmdcoma.Enabled = False 'nuevo
If Cmdigual.Tag = 0 Then
On Error GoTo fallo
If Command2(4).Tag = 5 Then
Command2(4).Tag = Command2(6).Tag
End If
If (Command2(4).Tag <> 0) And (Label1.Caption <> "") Then
Command2(1).Enabled = True
Command2(2).Enabled = True
Command2(3).Enabled = True

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas