GAMBAS

INTRODUCCION
Es un lenguaje de programación libre derivado de BASIC. Es similar al producto de Microsoft Visual Basic y se distribuye con licencia GNU GPL. Cabe destacar que presenta ciertas similitudes con Java ya que en la ejecución de cualquier aplicación, se requiere un conjunto de librerías interprete previamente instaladas (Gambas Runtime) que entiendan el bytecode de las aplicaciones desarrolladas y lo conviertan en codigo ejecutable por el computador. Por otro lado, a diferencia de Java, no se experimentan ralentizaciones y es posible desarrollar grandes aplicaciones en poco tiempo.
Permite crear formularios con botones de comandos, cuadros de texto y muchos otros controles y enlazarlos a bases de datos como MySQL, PostgreSQL o SQLite además de facilitar la creación de aplicaciones muy diversas como videojuegos (utilizando OpenGL), aplicaciones para dispositivos moviles (en desarrollo pero muy avanzado), aplicaciones de red (con manejo avanzado de protocolos HTTP, FTP, SMTP, DNS), entre otras .
Componentes
Un
compilador.
Un
intérprete.
Un
archivador.
Una
interfaz gráfica de usuario GUI.
Un
entorno de desarrollo.

*MENU*

*CLAVE*

PUBLIC c AS Integer
PUBLIC n AS String
PUBLIC SUB TextBox1_Change()

TextBox2.Enabled = TRUE
END
PUBLIC SUB TextBox2_KeyPress()
IF Key।Code = 65293 THEN

IF TextBox1।Text = "" THEN

Message.Info("Ingrese Clave de Usuario...")
TextBox1.SetFocus
ELSE
Button1.Enabled = TRUE
Button2.Enabled = TRUE
Button1.SetFocus
ENDIF
ENDIF
END
PUBLIC SUB Form_Open()
ME.Center
modulo.conectar
modulo.rs = modulo.cn.Exec("select * from claves")
n = "Administrador"
END
PUBLIC SUB Button1_Click()
DIM ban AS Integer
DO WHILE modulo.rs.Available
n = modulo.rs["usuario"]
IF modulo.rs["usuario"] = Trim(TextBox1.Text) AND modulo.rs["contrasena"] = Trim(TextBox2.Text) थें

modulo.rs = modulo.cn.Exec("select * from claves where usuario = '" & Trim(TextBox1.Text) & "'")
Message.Info("Bienvenido al sistema Sr. " & n, "Aceptar")
ME.Hi

menuprincipal.Show

ban = 1
ENDIF
modulo.rs.MoveNext()
LOOP
IF ban = 0 THEN
c = c + 1
IF c = 3 THEN
Message.Warning("Lo sentimos, El sistema se cerrar por seguridad.")
ME.Close
ELSE
limpiar()
TextBox1.SetFocus
Message.Error("Usuario desconocido, intente nuevamente...", "Aceptar")
ENDIF
END IF
END

PUBLIC SUB TextBox1_KeyPress()
IF Key.Code = 65293 THEN
IF TextBox1.Text = "" THEN
Message.Info("Ingrese Nombre de Usuario...")
TextBox1.SetFocus
ELSE
TextBox2.SetFocus
ENDIF
ENDIF
END
PUBLIC SUB limpiar()
Button1.Enabled = FALSE
Button2.Enabled = FALSE
TextBox1.Clear
TextBox2.Clear
TextBox2.Enabled = FALSE
TextBox1.SetFocus
END
PUBLIC SUB Button2_Click()
limpiar()
END
*INVENTARIO*
PUBLIC con AS Integer
PUBLIC fil AS Integer
PUBLIC col AS Integer
PUBLIC SUB Form_Open()
Modulo.conectar
Modulo.rs = modulo.cn.Exec("select * from Producto")
mostrar()
END
PUBLIC SUB Button5_Click()
ME.Close
END
PUBLIC SUB Button2_Click()
TRY Modulo.cn.Exec("insert into Producto values('" & Trim(UCase(TextBox1.Text)) & "','" & Trim(UCase(TextBox2.Text)) & "','" & (TextBox3.Text) & "','" & (ValueBox2.Text) & "');")
IF ERROR THEN
Message.Error("Imposible insertar el registro")
ELSE
Message.Info("Registro insertado")
END IF
Modulo.rs = Modulo.cn.Exec("Select * from Producto")
mostrar()
limpiar()
END

PUBLIC SUB Button3_Click()
SELECT Message.Question("Desea eliminar un Producto", "Si", "No")
CASE 1
TRY Modulo.cn.Exec("Delete from Producto where codigo='" & Trim(UCase(TextBox1.Text)) & "'")
IF ERROR THEN
Message.Error("Imposible borrar el registro")
ELSE
Modulo.rs = Modulo.cn.Exec("select * from Producto")
mostrar()
END IF
CASE 2
Message.Info("Registro no eliminado")
CASE 3
END SELECT
limpiar()
END
PUBLIC SUB Button4_Click()
DIM ban AS Integer
Modulo.rs = Modulo.cn.Exec("select * from Producto")
DO WHILE Modulo.rs.Available
IF modulo.rs["Codigo"] = Trim(UCase(TextBox1.Text)) THEN
Modulo.rs = Modulo.cn.Exec("select * from Producto where Codigo = '" & Trim(UCase(TextBox1.Text)) & "'")
TextBox2.Text = Modulo.rs["Nombre"]
TextBox3.Text = Modulo.rs["Precio"]
ValueBox2.Value = Modulo.rs["Cantidad"]
ban = 1
ENDIF
MODULO.rs.MoveNext()
LOOP
IF ban = 0 THEN
Message.Error("Registro Invalido")
limpiar()
END IF
END
PUBLIC SUB limpiar()
TextBox1.Clear
TextBox2.Clear
TextBox3.Clear
TextBox3.Text = 0
ValueBox2.Clear
END
PUBLIC SUB Grid1_DblClick()
IF Grid1.Current = NULL THEN RETURN
SELECT Message.Question("Desea eliminar un Producto", "Si", "No", "Ayuda")
CASE 1
TRY Modulo.cn.Exec("Delete from Producto where Codigo='" & Trim(UCase(Grid1.Current.Text)) & "'")
IF ERROR THEN
Message.Error("Imposible borrar el registro")
ELSE
Modulo.rs = Modulo.cn.Exec("select * from Producto")
mostrar()
END IF
CASE 2
Message.Info("Registro no eliminado")
CASE 3
END SELECT
Grid1.Columns.Width = 100
END
PUBLIC SUB Grid1_Click()
END
PUBLIC SUB Button6_Click()
TRY Modulo.cn.Exec("update Producto set Nombre='" & Trim(UCase(TextBox2.Text)) & "',Precio='" & Trim(UCase(TextBox3.Text)) & "',Cantidad='" & Trim(UCase(ValueBox2.Text)) & "' where codigo='" & Trim(TextBox1.Text) & "'")
IF ERROR THEN
Message.Error("Imposible actualizar el registro")
ELSE
Message.Info("Registro actualizado")
END IF
mostrar()
limpiar()
END
PUBLIC SUB Button1_Click()
limpiar
END
*PROVEEDOR*
PUBLIC SUB mostrar()
Modulo.rs.MoveFirst
IF Modulo.rs.Count > 0 THEN
Grid1.Columns.Count = 4
Grid1.Rows.Count = Modulo.rs.Count + 1
Grid1.Columns[1].Width = 30
Grid1.Columns[1].Width = 30
Grid1[0, 0].Text = "Codigo"
Grid1[0, 1].Text = "Nombre"
Grid1[0, 3].Text = "Precio Unitario"
Grid1[0, 2].Text = "Cantidad"
fil = 1
Modulo.rs.MoveFirst
'con = Modulo.rs.Count
DO WHILE Modulo.rs.Available
Grid1[fil, 0].Text = Modulo.rs["Codigo"]
Grid1[fil, 1].Text = Modulo.rs["Nombre"]
Grid1[fil, 2].Text = Modulo.rs["Cantidad"]
Grid1[fil, 3].Text = Modulo.rs["Precio"]
fil = fil + 1
Modulo.rs.MoveNext()
LOOP
ENDIF
END
*INGRESO DE USUARIO*
PUBLIC fil AS Integer
PUBLIC SUB TextBox1_Change()
TextBox2.Enabled = TRUE
END
PUBLIC SUB Button3_Click()
TRY modulo.cn.Exec("update into claves values('" & ("idclave") & "','" & Trim(TextBox1.Text) & "', '" & Trim(TextBox2.Text) & "' )")
IF ERROR THEN
Message.Error("Imposible actualizar el registro")
ELSE
Message.Info("Registro actualizado")
END IF
mostrar()
limpiar()
END
PUBLIC SUB limpiar()
TextBox1.Clear
TextBox2.Clear
END
PUBLIC SUB mostrar()
modulo.rs.MoveFirst
IF modulo.rs.Count > 0 THEN
GridView1.Columns.Count = 3
GridView1.Rows.Count = modulo.rs.Count + 1
GridView1.Columns[0].Width = 50
GridView1.Columns[1].Width = 250
GridView1.Columns[2].Width = 250
GridView1[0, 0].Text = "idclave"
GridView1[0, 1].Text = "usuario"
GridView1[0, 2].Text = "contrasena"
fil = 1
modulo.rs.MoveFirst
DO WHILE modulo.rs.Available
GridView1[fil, 0].Text = modulo.rs["idclave"]
GridView1[fil, 1].Text = modulo.rs["usuario"]
GridView1[fil, 2].Text = modulo.rs["contrasena"]
fil = fil + 1
modulo.rs.MoveNext()
LOOP
ENDIF
END
PUBLIC SUB Form_Open()
ME.Center
modulo.conectar
modulo.rs = modulo.cn.Exec("select * from claves")
mostrar()
desbotones()
END
PUBLIC SUB TextBox1_KeyPress()
IF Key.Code = 65293 THEN
IF TextBox1.Text = "" THEN
Message.Info("Ingrese Nombre de Usuario...")
TextBox1.SetFocus
ELSE
TextBox2.SetFocus
ENDIF
ENDIF
END
PUBLIC SUB TextBox2_KeyPress()
IF Key.Code = 65293 THEN
IF TextBox1.Text = "" THEN
Message.Info("Ingrese Clave de Usuario...")
TextBox1.SetFocus
ELSE
habotones()
Button3.SetFocus
ENDIF
ENDIF
END
PUBLIC SUB desbotones()
Button3.Enabled = FALSE
Button4.Enabled = FALSE
Button5.Enabled = FALSE
END
PUBLIC SUB habotones()
Button3.Enabled = TRUE
Button4.Enabled = TRUE
Button5.Enabled = TRUE
END
PUBLIC SUB Button6_Click()
menuprincipal.Show
ME.Hide
END
PUBLIC SUB Button2_Click()
TRY modulo.cn.Exec("insert into claves values('" & ("idclave") & "','" & Trim(TextBox1.Text) & "', '" & Trim(TextBox2.Text) & "' )")
IF ERROR THEN
Message.Error("Imposible Ingresar el usuario...")
ELSE
Message.Info("Usuario Ingresado...")
ENDIF
modulo.rs = modulo.cn.Exec("select * from claves")
mostrar()
limpiar()
END
PUBLIC SUB Button4_Click()
SELECT Message.Question("Desea eliminar una claves", "Si", "No")
CASE 1
TRY Modulo.cn.Exec("Delete from claves where usuario='" & Trim(UCase(TextBox1.Text)) & "'")
IF ERROR THEN
Message.Error("Imposible borrar el registro")
ELSE
Modulo.rs = Modulo.cn.Exec("select * from claves")
mostrar()
END IF
CASE 2
Message.Info("Registro no eliminado")
CASE 3
END SELECT
limpiar()
END
PUBLIC SUB Button5_Click()
DIM ban AS Integer
Modulo.rs = Modulo.cn.Exec("select * from claves")
DO WHILE Modulo.rs.Available
IF modulo.rs["usuario"] = Trim(UCase(TextBox1.Text)) THEN
Modulo.rs = Modulo.cn.Exec("select * from claves where usuario = '" & Trim(UCase(TextBox1.Text)) & "'")
TextBox1.Text = Modulo.rs["usuario"]
TextBox2.Text = Modulo.rs["contrasena"]
ban = 1
ENDIF
MODULO.rs.MoveNext()
LOOP
IF ban = 0 THEN
Message.Error("Registro Invalido")
limpiar()
END IF
END













PUBLIC SUB Main()
DIM a, b, c AS Integer
PRINT "Ingrese Valor A->:"
INPUT a
PRINT "Ingrese Valor B->:"
INPUT b
PRINT "Ingrese Valor C->:"
INPUT c
IF ((a > b) AND (a > c)) THEN
PRINT "Mayor", a
IF (b > c) THEN
PRINT "Medio->", b
PRINT "Menor->", c
ELSE
PRINT "Medio", c
PRINT "Menor", b
ENDIF
ENDIF
IF ((b > c) AND (b > a)) THEN
PRINT "Mayor", b
IF (a > c) THEN
PRINT "Medio->", a
PRINT "Menor->", c
ELSE
PRINT "Medio->", c
PRINT "Menor->", a
ENDIF
ENDIF
IF ((c > b) AND (c > a)) THEN
PRINT "Mayor->", c
IF (b > a) THEN
PRINT "Medio", b
PRINT "Menor", a
ELSE
PRINT "Medio", a
PRINT "Menor", b
ENDIF
ENDIF
END

*INGRESAR TRES PARCIALES CALCULAR LA SUMA, EL PROMEDIO, SI APRUEBA, O SE QUEDA A RECUPERACION
*ADEMAS LA EQUIVALENCIA DE SEGUN LA SIGUIENTE TABLA:10 SOBRESALIENTE,9-8 MUY BUENA,7 BUENA, 6-1 INSUFICIENTE *
PUBLIC SUB Main()
DIM N1, N2, N3 AS Integer
PRINT "INGRESE NOTA UNO"
INPUT N1
PRINT " INGRESAR NOTA DOS"
INPUT N2
PRINT " INGRESAR NOTA TRES"
INPUT N3
PRINT "LA SUMA ES", Module1.SUMA(N1, N2, N3)
PRINT "EL PROMEDIO ES", Module1.PROMEDIO(N1, N2, N3)
PRINT "LA EQUILALENCIA ES", Module1.EQUIVALENCIA(N1, N2, N3)
PRINT "OBSERVACION", Module1.OBSERVACION(N1, N2, N3)
END
PUBLIC FUNCTION SUMA(v1 AS Integer, v2 AS Integer, v3 AS Integer) AS Integer
DIM su AS Integer
su = v1 + v2 + v3
RETURN su
END
PUBLIC FUNCTION PROMEDIO(v1 AS Integer, v2 AS Integer, v3 AS Integer) AS Integer
DIM prom AS Integer
prom = (v1 + v2 + v3) DIV 3
RETURN prom
END
PUBLIC FUNCTION EQUIVALENCIA(v1 AS Integer, v2 AS Integer, v3 AS Integer) AS String
DIM eq AS Integer
DIM e AS String
eq = (v1 + v2 + v3) DIV 3
IF (eq < e = "insuificiente" eq =" 7)" e = "BUENO" e = "muy BUENO" e = "SOBRESALIENTE" eq =" (v1" e = "REPROBADO" e = "RECUPERACION" e = "APRUEBA">

PUBLIC SUB Main()
DIM ced, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 AS String
DIM d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, u, s, r AS Integer
PRINT "ingrese numero de cedula"
INPUT ced
c1 = Mid(ced, 1, 1)
c2 = Mid(ced, 2, 1)
c3 = Mid(ced, 3, 1)
c4 = Mid(ced, 4, 1)
c5 = Mid(ced, 5, 1)
c6 = Mid(ced, 6, 1)
c7 = Mid(ced, 7, 1)
c8 = Mid(ced, 8, 1)
c9 = Mid(ced, 9, 1)
c10 = Mid(ced, 10, 1)
d1 = Val(c1) * 2
IF (d1 >= 10) THEN d1 = d1 - 9
d2 = Val(c2)
d3 = Val(c3) * 2
IF (d3 >= 10) THEN d3 = d3 - 9
d4 = Val(c4)
d5 = Val(c5) * 2
IF (d5 >= 10) THEN d5 = d5 - 9
d6 = Val(c6)
d7 = Val(c7) * 2
IF (d7 >= 10) THEN d7 = d7 - 9
d8 = Val(c8)
d9 = Val(c9) * 2
IF (d9 >= 10) THEN d9 = d9 - 9
s = d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10
r = s MOD 10
IF (s = 10) THEN
u = 0
ELSE
u = 10 - r
END IF
d10 = Val(c10)
IF (u = d10) THEN
PRINT "numero correcto"
ELSE
PRINT "numero incorrecto"
END IF
END

PUBLIC ban AS Integer
PUBLIC aux1 AS Integer
PUBLIC aux AS Integer
PUBLIC compunto AS Integer
'PUBLIC cadena AS String
'PUBLIC cadena2 AS String
PUBLIC SUB Form_Open()
END
PUBLIC SUB Button12_Click()
ban = 1
IF visor.text <> 0 THEN
aux1 = visor.text
ELSE
aux1 = 0
ENDIF
visor.clear
END
PUBLIC SUB Button8_Click()
visor.text = visor.text & "1"
END
PUBLIC SUB Button9_Click()
visor.text = visor.text & "2"
END
PUBLIC SUB Button10_Click()
visor.text = visor.text & "3"
END
PUBLIC SUB Button4_Click()
visor.text = visor.text & "4"
END
PUBLIC SUB Button5_Click()
visor.text = visor.text & "5"
END
PUBLIC SUB Button6_Click()
visor.text = visor.text & "6"
END
PUBLIC SUB Button1_Click()
visor.text = visor.text & "7"
END
PUBLIC SUB Button2_Click()
visor.text = visor.text & "8"
END
PUBLIC SUB Button3_Click()
visor.text = visor.text & "9"
END
PUBLIC SUB Button7_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 Button16_Click()
ME.CLOSE
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
aux = visor.text
ELSE
aux = 0
ENDIF
visor.text = operaciones(ban, aux1, aux)
END
PUBLIC FUNCTION operaciones(opera AS Integer, v1 AS Integer, v2 AS Integer) AS Integer
DIM respuesta AS Integer
DIM i AS Integer
DIM acumula AS Integer
SELECT CASE opera
CASE 1
respuesta = v1 + v2
CASE 2
respuesta = v1 - v2
CASE 3
respuesta = v1 * v2
CASE 4
IF v2 = 0 THEN
respuesta = v1 / v2
Message("dividir para cero informacion")
ENDIF
CASE 5
acumula = 1
FOR i = 1 TO v2
acumula = acumula * v1
NEXT
respuesta = acumula
END SELECT
RETURN respuesta
END
PUBLIC SUB Button19_Click()
visor.Text = visor.text * visor.Text
END
PUBLIC SUB Button21_Click()
IF visor.Text <> "" THEN
compunto = 0
ban = 5
IF visor.Text <> 0 THEN
aux1 = visor.Text
ELSE
aux1 = 0
ENDIF
visor.Clear
ENDIF
END
PUBLIC SUB Button20_Click()
visor.Text = visor.Text * visor.Text * visor.Text
END
PUBLIC SUB Button28_Click()
END
PUBLIC SUB Button23_Click()
visor.Text = Sin(visor.Text)
END
PUBLIC SUB Button24_Click()
visor.Text = Cos(visor.Text)
END
PUBLIC SUB Button25_Click()
visor.Text = Tan(visor.Text)
END
PUBLIC SUB Button32_Click()
DIM c, oc1, oc2, i AS Integer
DIM cadena, cadena2 AS String
c = visor.Text
WHILE c > 0
oc1 = (Int(c / 8))
oc2 = c MOD 8
cadena = cadena & Str(oc2)
c = oc1
WEND
FOR i = Len(cadena) TO 1 STEP - 1
cadena2 = cadena2 & Mid(cadena, i, 1)
NEXT
visor.Text = cadena2
END
PUBLIC SUB Button33_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 END PUBLIC SUB Button22_Click() END PUBLIC SUB Button26_Click() END PUBLIC SUB Button30_Click() END PUBLIC SUB Button29_Click() DIM i AS Integer FOR i = 1 TO visor.Text IF i <> visor.text
visor.text = i
ENDIF
NEXT
END

*MENU*


fmain
PUBLIC SUB Reloj_Click()
Form1.Show
END
PUBLIC SUB Exit_Click()
ME.Close
END


*CRONOMETRO*

PUBLIC s AS Integer
PUBLIC m AS Integer
PUBLIC h AS Integer
PUBLIC SUB Timer1_Timer()
s = TextBox1.Text
m = TextBox2.Text
h = TextBox3.Text
IF s < s =" s" s =" 0" m =" m"> 59 THEN
h = h + 1
m = 0
END IF
ENDIF
TextBox1.Text = s
TextBox2.Text = m
TextBox3.Text = h
END
PUBLIC SUB Button1_Click()
IF Button1.Text = "Iniciar" OR Button1.Text = "Reiniciar" THEN
Timer1.Enabled = TRUE
Button1.Text = "Parar"
ELSE
Timer1.Enabled = FALSE
Button1.Text = "Reiniciar"
ENDIF
END


PUBLIC SUB Button2_Click()
FMain.Show
END


*JUEGO*
PUBLIC a AS Integer
PUBLIC b AS Integer
PUBLIC c AS Integer
PUBLIC SUB Button1_Click()
Timer1.Enabled = TRUE
END
PUBLIC SUB Timer1_Timer()
DIM a, b, c AS Integer
TextBox4.Clear
RANDOMIZE
a = (Rnd * 10) + 1
TextBox1.text = a
'Message("este el el numero" & TextBox1.Text)
b = (Rnd * 10) + 1
TextBox2.text = b
c = (Rnd * 10) + 1
TextBox3.text = c
END
PUBLIC SUB Button2_Click()
Timer1.Enabled = FALSE
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
IF a = b AND b = c AND a = c THEN
TextBox4.text = "GANO"
ELSE
TextBox4.Text = "INTENTE OTRA VEZ"
ENDIF
TextBox1.Text = a
TextBox2.Text = b
TextBox3.Text = c
IF TextBox4.Text = "GANO" THEN
TextBox7.Text = TextBox5.Text * TextBox6.Text
Message("APUESTA GANADA")
ELSE
TextBox7.Text = 0
TextBox1.Clear
TextBox2.Clear
TextBox3.Clear
TextBox5.Clear
TextBox6.Clear
Message("Apuesta Perdida")
ENDIF
END
PUBLIC SUB Button3_Click()
FMain.Show
END