Paso 1.
El primer paso que vamos a hacer es el diseño de la calculadora por lo cual vamos a necesitar varios commandbutton 18 en total los primeros 12 son los numero del 0 al 9 el punto y el igual los otros cuatro son los simbolos de las ecuaciones +,-,* y / y dos mas con la opcion de borrar y nuevo.
Tambien pones un textbox que sera el q nos permita visulizar los numeros ingresados.
Paso 2.
El segundo paso es ingresar los codigos en cada boton como son bastantes commandbutton seran bastantes codigos ya q se aplica a cada uno
Dim num1 As Integer
Dim num2 As Integer
Dim op As String
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & 7
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text & "."
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text & 0
End Sub
Operaciones
Private Sub Command12_Click()
If (num1 = 0) Then
MsgBox ("no realizo una operacion")
Else
num2 = Text1.Text
If op = "+" Then
Text1.Text = num1 + num2
End If
If op = "-" Then
Text1.Text = num1 - num2
End If
If op = "*" Then
Text1.Text = num1 * num2
End If
If op = "/" Then
Text1.Text = num1 / num2
End If
End If
End Sub
Suma
Private Sub Command13_Click()
num1 = Text1.Text
Text1.Text = ""
op = "+"
Text1.SetFocus
End Sub
Resta
Private Sub Command14_Click()
num1 = Text1.Text
Text1.Text = ""
op = "-"
Text1.SetFocus
End Sub
Multiplicacion
Private Sub Command15_Click()
num1 = Text1.Text
Text1.Text = ""
op = "*"
Text1.SetFocus
End Sub
Divicion
Private Sub Command16_Click()
num1 = Text1.Text
Text1.Text = ""
op = "/"
Text1.SetFocus
End Sub
Borrar
Private Sub Command17_Click()
Text1.Text = ""
Text1.SetFocus
End Sub
Nuevo
Private Sub Command18_Click()
Text1.Text = ""
Text1.SetFocus
End Sub
Numero 8
Private Sub Command2_Click()
Text1.Text = Text1.Text & 8
End Sub
Numero 9
Private Sub Command3_Click()
Text1.Text = Text1.Text & 9
End Sub
Numero 4
Private Sub Command4_Click()
Text1.Text = Text1.Text & 4
End Sub
Numero 5
Private Sub Command5_Click()
Text1.Text = Text1.Text & 5
End Sub
Numero 6
Private Sub Command6_Click()
Text1.Text = Text1.Text & 6
End Sub
Numero 1
Private Sub Command7_Click()
Text1.Text = Text1.Text & 1
End Sub
Numero 2
Private Sub Command8_Click()
Text1.Text = Text1.Text & 2
End Sub
Numero 3
Private Sub Command9_Click()
Text1.Text = Text1.Text & 3
End Sub
Paso 3.
Despues de ingresar los codigos ponemos ejecutar y con eso podremos ver si todos los botones funcionan con sus respectivos comandos.


No hay comentarios:
Publicar un comentario