jueves, 2 de junio de 2016

Calculadora

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.


Las 4 ecuaciones

Paso 1.

El primer paso son ingresar los cuadros q vamos a utilizar 3 textbox, 3 label con los escritos ingrese el primer numero ingrese el segundo  resultado y 4 commandbutton cada uno con su nombre suma, resta, multiplicacion y divicion.


Paso 2.

Como segundo paso lo q aremos es poner los codigos de cada ecuacion para asi poder hacer q funcione nuestros botones 
Suma
Private Sub Command1_Click()
a = Val(Text1)
b = Val(Text2)
Text3 = a + b

End Sub
Resta
Private Sub Command2_Click()
a = Val(Text1)
b = Val(Text2)
Text3 = a - b

End Sub
Multiplicacion
Private Sub Command3_Click()
a = Val(Text1)
b = Val(Text2)
Text3 = a * b

End Sub
Divicion
Private Sub Command4_Click()
a = Val(Text1)
b = Val(Text2)
Text3 = a / b

End Sub


Paso 3.
Lo que hacemos es ejecutar el programa y probar las ejecuciones con el fin de que nos salgan los resultados exactos.