
LOS BOTONES donde se ponen los números es una matriz de controles, también donde están los operadores son matriz de controles, “esto es para ahorrar líneas de código”
CODIGO_______________________________________________________________
'declaramos un variable de tipo carácter, donde se almacenara los operadores como +, -, *, / etc.
Dim operador As String
'declaramos tres variables, donde res almacenara el resultado de la operación y var, var1, los datos ingresados por el usuario
Dim VAR, var1, res As Double
Private Sub Command1_Click(Index As Integer)
'valor del caption de cada boton dentro de la matriz se mostrara en la caja de testo de nombre pantalla
pantalla.Text = pantalla.Text & Command1(Index).Caption
End Sub
Private Sub Command11_Click()
'boton borrar un numero
pantalla.Text = StrReverse(Mid(StrReverse(pantalla.Text), 2))
End Sub
Private Sub Command12_Click()
'boton raiz cuadrada
pantalla.Text = Sqr(Val(pantalla.Text))
End Sub
Private Sub Command2_Click()
'borrar la pantalla
pantalla.Text = ""
End Sub
Private Sub Command4_Click()
'boton igual
'compara si la pantalla esta en blanco
If pantalla.Text = "" Then
Else
' almacena el segundo numero y limpia la pantalla
var1 = pantalla.Text
pantalla.Text = ""
Select Case operador
'selecciona el valor que tiene lavariable operador
Case "-": res = Val(VAR) - Val(var1)
Case "+": res = Val(VAR) + Val(var1)
Case "*": res = Val(VAR) * Val(var1)
Case "/": Call divi0
Case "\": Call ente0
Case "MOD": Call modu
Case "%": Call porce
End Select
pantalla.Text = res
End If
End Sub
Private Sub Command5_Click(Index As Integer)
'botones de los operadores almacenados en una matriz de controles
'comprueba si la pantalla esta en blanco
If pantalla.Text = "" Then
Else
'almacena el numero en pantalla y luego la limpia
VAR = pantalla.Text
pantalla.Text = ""
'almacena el caption de cualqiuer boton de operacion en la variable operador
operador = Command5(Index).Caption
End If
End Sub
Private Sub Command6_Click()
'boton borrar
End
End Sub
Private Sub Command9_Click()
'boton cero
If pantalla.Text = "0" Then
pantalla.Text = pantalla.Text & ".0"
Else
pantalla.Text = pantalla.Text & Command9.Caption
End If
End Sub
Private Sub Form_Load()
'carga el valor a los botones de los números
For i = 1 To 9
Command1(i).Caption = i
Next
Command9.Caption = 0
End Sub
Function divi0()
' funcion que comprueba que si el valor a dividicion por cero le avise al susuario de lo contrario realiza la divicion
If var1 = 0 Then
MsgBox "NO ES POSIBLE LA DIVISION POR CERO (0) "
Else
res = VAR / var1
End If
End Function
Function ente0()
' funcion que comprueba que si el valor a dividicion entera es por cero le avise al susuario de lo contrario realiza la divicion entera
If var1 = 0 Then
MsgBox "NO ES POSIBLE LA DIVISION ENTERA POR CERO (0) "
Else
res = VAR \ var1
End If
End Function
Function modu()
' funcion que comprueba que si el valor a dividir es por cero le avise al susuario de lo contrario realiza la modulo
If var1 = 0 Then
MsgBox "NO ES POSIBLE HALLAR EL MODULO POR CERO (0)"
Else
res = VAR Mod var1
End If
End Function
Function porce()
' funcion que comprueba que si el valor a dividir es por cero le avise al susuario de lo contrario realiza la porcentaje
If var1 = 0 Then
MsgBox "NO ES POSIBLE HALLAR EL 0% DE " & VAR
Else
res = (VAR * var1) / 100
End If
End Function