Calculadora

716 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
716
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
24
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Calculadora

  1. 1. Calculadora en la programación en GAMBAS PUBLIC CAN AS Integer PUBLIC OPE1 AS Single PUBLIC OPE2 AS Single PUBLIC SUB Button17_Click() TextBox1.Clear() END PUBLIC SUB Button18_Click() ME.Close(0) END PUBLIC SUB Button12_Click() TextBox1.Text = TextBox1.Text & "0" END
  2. 2. PUBLIC SUB Button13_Click() TextBox1.Text = TextBox1.Text & "." END PUBLIC SUB Button7_Click() TextBox1.Text = TextBox1.Text & "1" END PUBLIC SUB Button8_Click() TextBox1.Text = TextBox1.Text & "2" END PUBLIC SUB Button9_Click() TextBox1.Text = TextBox1.Text & "3" END PUBLIC SUB Button4_Click() TextBox1.Text = TextBox1.Text & "4" END PUBLIC SUB Button5_Click() TextBox1.Text = TextBox1.Text & "5" END PUBLIC SUB Button6_Click() TextBox1.Text = TextBox1.Text & "6" END PUBLIC SUB Button1_Click() TextBox1.Text = TextBox1.Text & "7" END PUBLIC SUB Button2_Click() TextBox1.Text = TextBox1.Text & "8"
  3. 3. END PUBLIC SUB Button3_Click() TextBox1.Text = TextBox1.Text & "9" END PUBLIC SUB Button10_Click() CAN = 4 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Clear END PUBLIC SUB Button15_Click() CAN = 1 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Clear END PUBLIC SUB Button14_Click() CAN = 2 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Clear END PUBLIC SUB Button11_Click() CAN = 3
  4. 4. IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Clear END PUBLIC SUB Button16_Click() IF TextBox1.Text <> 0 THEN OPE2 = TextBox1.Text ELSE OPE2 = 0 ENDIF TextBox1.Text = operacion(OPE1, OPE2, CAN) END PUBLIC FUNCTION operacion(v1 AS Float, v2 AS Float, opera AS Integer) AS Float DIM re AS Float DIM X, Y, Z, X1, Y1, Z1, X2, Y2, Z2, f, i AS Integer DIM XX, MEA AS String SELECT CASE opera CASE 1 re = v1 + v2 CASE 2 re = v1 - v2 CASE 3 re = v1 * v2 CASE 4 re = v1 / v2 CASE 5 re = (v1 * v2) / 100 CASE 6 re = v1 ^ 2 Z2 = 1 CASE 7 re = v1 ^ 3 Z2 = 1 CASE 8 re = v1 ^ v2 Z2 = 1 CASE 9 re = 1 / v1
  5. 5. Z2 = 1 CASE 10 f=1 FOR i = 1 TO v1 f=f*i NEXT re = f Z2 = 1 END SELECT IF Z2 = 1 THEN RETURN re ELSE RETURN Y1 ENDIF END PUBLIC SUB Button19_Click() CAN = 5 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Clear END PUBLIC SUB Button20_Click() CAN = 6 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Text = OPE1 END PUBLIC SUB Button21_Click() 'numero binario DIM valor, x1, x2, i AS Integer DIM cadena, cadena2 AS String valor = TextBox1.Text
  6. 6. WHILE valor > 0 x1 = valor MOD 2 x2 = Int(valor / 2) cadena = cadena & Str(x1) valor = x2 WEND FOR i = Len(cadena) TO 1 STEP -1 cadena2 = cadena2 & (Mid(cadena, i, 1)) NEXT TextBox1.Text = cadena2 END PUBLIC SUB Button22_Click() 'Calculo a octal de un número decimal DIM valor, x1, x2, i AS Integer DIM cadena, cadena2 AS String ' IF visor.Text <> 0 THEN valor = TextBox1.Text WHILE valor > 0 x1 = valor MOD 8 x2 = Int(valor / 8) cadena = cadena & Str(x1) valor = x2 WEND FOR i = Len(cadena) TO 1 STEP -1 cadena2 = cadena2 & (Mid(cadena, i, 1)) NEXT TextBox1.Text = cadena2 END PUBLIC SUB Button23_Click() 'Calculo a hexadecimal de un número decimal DIM valor, x1, x2, i AS Integer DIM cadena, cadena2 AS String valor = TextBox1.Text WHILE valor > 0 x1 = valor MOD 16 x2 = Int(valor / 16) IF x1 = 10 THEN cadena = cadena & "A" ELSE IF x1 = 11 THEN cadena = cadena & "B" ELSE IF x1 = 12 THEN cadena = cadena & "C"
  7. 7. ELSE IF x1 = 13 THEN cadena = cadena & "D" ELSE IF x1 = 14 THEN cadena = cadena & "E" ELSE IF x1 = 15 THEN cadena = cadena & "F" ELSE cadena = cadena & Str(x1) ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF valor = x2 WEND FOR i = Len(cadena) TO 1 STEP -1 cadena2 = cadena2 & (Mid(cadena, i, 1)) NEXT TextBox1.Text = cadena2 END PUBLIC SUB Button24_Click() CAN = 7 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Text = OPE1 END PUBLIC SUB Button25_Click() CAN = 8 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Text = OPE1 END
  8. 8. PUBLIC SUB Button28_Click() DIM k AS Float k = Rad(TextBox1.Text) TextBox1.Text = Sin(k) END PUBLIC SUB Button29_Click() DIM k AS Float k = Rad(TextBox1.Text) TextBox1.Text = Cos(k) END PUBLIC SUB Button30_Click() DIM k AS Float k = Rad(TextBox1.Text) TextBox1.Text = Tan(k) END PUBLIC SUB Button26_Click() CAN = 9 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Text = OPE2 END PUBLIC SUB Button27_Click() CAN = 10 IF TextBox1.Text <> 0 THEN OPE1 = TextBox1.Text ELSE OPE1 = 0 ENDIF TextBox1.Text = OPE2 END

×