CALCULADORA
En este formulario utilizamos 1 Label, 1 TextBox, 33 Button.
PUBLIC ban AS IntegerPUBLIC aux1 AS Integer
PUBLIC aux2 AS Integer
PUBLIC Sin AS Integer
PUBLIC SUB Button16_Click()
ME.Close
END
PUBLIC SUB Button1_Click()
visor.text = visor.text & "1"
END
PUBLIC SUB Button10_Click()
visor.text = visor.text & "2"
END
PUBLIC SUB Button9_Click()
visor.text = visor.text & "3"
END
PUBLIC SUB Button8_Click()
visor.text = visor.text & "4"
END
PUBLIC SUB Button7_Click()
visor.text = visor.text & "5"
END
PUBLIC SUB Button6_Click()
visor.text = visor.text & "6"
END
PUBLIC SUB Button5_Click()
visor.text = visor.text & "7"
END
PUBLIC SUB Button4_Click()
visor.text = visor.text & "8"
END
PUBLIC SUB Button3_Click()
visor.text = visor.text & "9"
END
PUBLIC SUB Button2_Click()
visor.text = visor.text & "0"
END
PUBLIC SUB Button11_Click()
visor.text = visor.text & "."
END
PUBLIC SUB Button17_Click()
visor.clear
END
PUBLIC SUB Button12_Click()
ban = 1
IF visor.text <> 0 THEN
aux1 = visor.text
ELSE
aux1 = 0
ENDIF
visor.Clear
END
PUBLIC SUB Button13_Click()
ban = 2
IF visor.text <> 0 THEN
aux1 = visor.text
ELSE
aux1 = 0
ENDIF
visor.Clear
END
PUBLIC SUB Button14_Click()
ban = 3
IF visor.text <> 0 THEN
aux1 = visor.text
ELSE
aux1 = 0
ENDIF
visor.Clear
END
PUBLIC SUB Button15_Click()
ban = 4
IF visor.text <> 0 THEN
aux1 = visor.text
ELSE
aux1 = 0
ENDIF
visor.Clear
END
PUBLIC SUB Button18_Click()
IF visor.text <> 0 THEN
aux2 = visor.Text
ELSE
aux2 = 0
ENDIF
visor.text = operaciones(ban, aux1, aux2)
END
PUBLIC FUNCTION operaciones(opera AS Integer, v1 AS Integer, v2 AS Integer) AS Integer
DIM respuesta AS Integer
SELECT CASE opera
CASE 1
respuesta = v1 + v2
CASE 2
respuesta = v1 - v2
CASE 3
respuesta = v1 * v2
CASE 4
respuesta = v1 / v2
END SELECT
RETURN respuesta
END
PUBLIC SUB Button19_Click()
visor.Text = visor.Text * visor.Text
END
PUBLIC SUB Button23_Click()
visor.Text = visor.Text * visor.Text * visor.Text
END
PUBLIC SUB Button20_Click()
visor.Text = Sin(visor.Text)
END
PUBLIC SUB Button25_Click()
END
PUBLIC SUB Button22_Click()
DIM n, x1, i, x2 AS Integer
DIM cadena, cadena2 AS String
n = visor.Text
WHILE n > 0
x1 = (Int(n / 2))
x2 = n MOD 2
cadena = cadena & Str(x2)
n = x1
WEND
FOR i = Len(cadena) TO 1 STEP -1
cadena2 = cadena2 & Mid(cadena, i, 1)
NEXT
visor.text = cadena2
Message("el reslutado es...", "aceptar")
END
PUBLIC SUB Button24_Click()
visor.Text = Cos(visor.Text)
END
PUBLIC SUB Button28_Click()
visor.Text = Tan(visor.Text)
END
PUBLIC SUB Button26_Click()
DIM a, b1, b2, k, respuesta AS Integer
DIM cade, cade1 AS String
a = visor.Text
WHILE a > 0
b1 = (Int(a / 8))
b2 = a MOD 8
cade = cade & Str(b2)
a = b1
WEND
FOR k = Len(cade) TO 1 STEP -1
cade1 = cade1 & Mid(cade, k, 1)
NEXT
visor.Text = cade1
END
PUBLIC SUB Button30_Click()
DIM n, i, x1, x2 AS Integer
DIM cadena, cadena2 AS String
n = visor.Text
WHILE n > 0
x1 = (Int(n / 16))
x2 = n MOD 16
IF x2 < 10 THEN
cadena = cadena & Str(x2)
ELSE IF x2 = 10 THEN
cadena = cadena & "A"
ELSE IF X2 = 11 THEN
cadena = cadena & "B"
ELSE IF x2 = 12 THEN
cadena = cadena & "C"
ELSE IF X2 = 13 THEN
cadena = cadena & "D"
ELSE IF x2 = 14 THEN
cadena = cadena & "E"
ELSE IF X2 = 15 THEN
cadena = cadena & "F"
ENDIF
n = x1
WEND
FOR i = Len(cadena) TO 1 STEP -1
cadena2 = cadena2 & Mid(cadena, i, 1)
NEXT
visor.Text = cadena2
Message("El resultado es ...", "Aceptar")
END
hola amigo adwin, primeramente gracias por el codigo hace mucho que necesitaba una calculadora en gambas... Pero tengo una dato para ti, deberias cambiar tu tipo de dato(de integer a float) ya que al hacer una operacion con punto decimal marca error.
ResponderEliminarsaludos