![]() |
||
3.- Calculadora Basica. Este ejercicio se realizara una aplicación que podrá hacer operaciones como suma, resta, multiplicación y división.
En el formulario se utilizara cuatro etiquetas, cuatro cajas de texto, cuatro botones de opción y tres botones de comando.
![]() Cuando ya tenemos a todos los objetos con su nombre, entonces seguimos con el código que se le aplicara a los tres botones. Empezamos por el botón Calcular.
Private Sub Cmd1_Click()
If OBtn1 = True Then
Text3 = Val(Text1) / Val(Text2)
ElseIf OBtn2 = True Then
Text3 = Val(Text1) * Val(Text2)
ElseIf OBtn3 = True Then
Text3 = Val(Text1) - Val(Text2)
ElseIf OBtn4 = True Then
Text3 = Val(Text1) + Val(Text2)
End If
End Sub
Después de haber terminado de escribir el código de el botón Calcular seguimos con el botón Nueva operación.
Private Sub Cmd2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text1.SetFocus
End Sub
Posteriormente codificamos el botón Salir Private Sub Cmd3_Click() End
End Sub
Y la aplicación de la calculadora queda terminada:
![]() |
|
|
![]() |