miércoles, 4 de noviembre de 2009

Código Formulario Menú

MENU
En este ejercicio utilizamos 3 formularios, Fmain (Menu), Form1 (Cronometro), Form2 (Juego).




MENU(FMain)
PUBLIC SUB Reloj_Click()
Form1.Show
END
PUBLIC SUB Juego_Click()
Form2.Show
END
PUBLIC SUB Yes_Click()
ME.Close
END

Cronometro(Form1)
En este formulario utilizamos 3 Label, 3 TextBox, 3 Button, 1 Timer.

PUBLIC s AS Integer
PUBLIC m AS Integer
PUBLIC h AS Integer
PUBLIC SUB Timer1_Timer()
s = TextBox1.Text
IF s < 59 THEN
s = s + 1
ELSE
IF m < 59 THEN
s = 0
m = m + 1
TextBox2.Text = m
ELSE
'horas
IF h < 23 THEN
m = 0
h = h + 1
TextBox3.Text = h
ELSE
' Timer1.Enabled = FALSE
' TextBox1.text = 0
' TextBox2.text = 0
' TextBox3.text = 0
s = 0
h = 0
m = 0
ENDIF
ENDIF
ENDIF
TextBox1.text = s
END
PUBLIC SUB Button1_Click()
IF Button1.Text = "Iniciar" THEN
Timer1.Enabled = TRUE
Button1.Text = "Parar"
ELSE
IF Button1.Text = "Parar" THEN
Timer1.Enabled = FALSE
Button1.Text = "iniciar"
ELSE
Timer1.Enabled = TRUE
Button1.Text = "Parar"
ENDIF
ENDIF
END
PUBLIC SUB Button2_Click()
IF Button2.Text = "Restaurar" THEN
Timer1.Enabled = FALSE
TextBox1.text = 0
TextBox2.text = 0
TextBox3.text = 0
s = 0
h = 0
m = 0
ENDIF
END
PUBLIC SUB Button3_Click()
ME.close
FMain.Show
END

Juego(Form2)
En este formulario utilizamos 1 Label, 3 TextBox, 3 Button, 1 Timer.

PUBLIC SUB Button1_Click()
Timer1.Enabled = TRUE
END
PUBLIC SUB Button2_Click()
ME.Close
FMain.Show
PUBLIC SUB Timer1_Timer()
DIM a, b, c AS Integer
RANDOMIZE
a = (Rnd * 10) + 1
TextBox1.Text = a
' Message("Este es el numero" & TextBox1.Text)
b = (Rnd * 10) + 1
TextBox2.Text = b
' Message("Este es el numero" & TextBox2.Text)
c = (Rnd * 10) + 1
TextBox3.Text = c
' Message("Este es el numero" & TextBox3.Text)
IF a = b AND b = c AND TextBox4.Text = a THEN
Message("Felicidades")
ENDIF
END
PUBLIC SUB Button3_Click()
Timer1.Enabled = FALSE
END

Código Calculadora

CALCULADORA
En este formulario utilizamos 1 Label, 1 TextBox, 33 Button.
PUBLIC ban AS Integer
PUBLIC 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

Código Digito Verificador

DIGITO VERIFICADOR
Este programa calcula el digito verificador de la cedula de identidad.

PUBLIC SUB Main()
DIM cedula, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10 AS String
DIM p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, suma, residuo, v AS Integer
PRINT "<<<>>>"
PRINT "INGRESE NUMERO"
INPUT cedula
n1 = Mid(cedula, 1, 1)
n2 = Mid(cedula, 2, 1)
n3 = Mid(cedula, 3, 1)
n4 = Mid(cedula, 4, 1)
n5 = Mid(cedula, 5, 1)
n6 = Mid(cedula, 6, 1)
n7 = Mid(cedula, 7, 1)
n8 = Mid(cedula, 8, 1)
n9 = Mid(cedula, 9, 1)
n10 = Mid(cedula, 10, 1)
p1 = Val(n1) * 2
IF (p1 >= 10) THEN p1 = p1 - 9
p2 = Val(n2)
p3 = Val(n3) * 2
IF (p3 >= 10) THEN p3 = p3 - 9
p4 = Val(n4)
p5 = Val(n5) * 2
IF (p5 >= 10) THEN p5 = p5 - 9
p6 = Val(n6)
p7 = Val(n7) * 2
IF (p7 >= 10) THEN p7 = p7 - 9
p8 = Val(n8)
p9 = Val(n9) * 2
IF (p9 >= 10) THEN p9 = p9 - 9
suma = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9
residuo = suma MOD 10
IF (suma = 10) THEN
v = 0
ELSE
v = 10 - residuo
ENDIF
p10 = Val(n10)
IF (v = p10) THEN
PRINT "EL NUMERO INGRESADO ES CORRECTO...!!"
ELSE
PRINT "EL NUMERO QUE INGRESO ES INCORRECTO, POR FAVOR VERIFIQUE Y VUELVA A INGRESARLO NUEVAMENTE ...??"
ENDIF

END

Código Funciones Y Hola Mundo

HOLA MUNDO
Este programa despliega por pantalla el texto “Hola Mundo”
PUBLIC SUB Main()
PRINT "Hola mundo"
END
FUNCIONES
En este programa utilizamos dos módulos el pricipal (MMain) y modulo 1, Calcula las operaciones
básicas suma, resta, multiplicación y división.
MMain
PUBLIC SUB Main()
DIM a, b AS Integer
PRINT "<<<>>>"
PRINT "Ingrese primer valor"
INPUT a
PRINT "Ingrese segundo valor"
INPUT b
PRINT opera(a, b)
PRINT opera1(a, b)
PRINT opera2(a, b)
PRINT opera3(a, b)
END
'funcion para sumar
PUBLIC FUNCTION opera(v1 AS Integer, v2 AS Integer) AS Integer
DIM suma AS Integer
suma = v1 + v2
PRINT "La suma es..."
RETURN suma
END
'funcion para restar
PUBLIC FUNCTION opera1(v1 AS Integer, v2 AS Integer) AS Integer
DIM resta AS Integer
resta = v1 - v2
PRINT "La resta es.."
RETURN resta
END
'funcion para multiplicar
PUBLIC FUNCTION opera2(v1 AS Integer, v2 AS Integer) AS Integer
DIM mult AS Integer
mult = v1 * v2
PRINT "La multiplicacion es..."
RETURN mult
END
'funcion para dividir
PUBLIC FUNCTION opera3(v1 AS Integer, v2 AS Integer) AS Integer
DIM divs AS Integer
divs = v1 DIV v2
PRINT "la division es..."
RETURN divs
END
modulo1
' Gambas module file
'funcion para sumar
PUBLIC SUB main()
DIM a, b AS Integer
PRINT "primer valor"
INPUT a
PRINT "sugundo valor"
INPUT b
PRINT "La suma es...", modulo1.suma(a, b)
PRINT "La resta es...", modulo1.resta(a, b)
PRINT "La multiplicacion es...", modulo1.multiplicacion(a, b)
PRINT "La division es...", modulo1.division(a, b)
END

Código Matricula

MATRICULA
Para este ejercicio de consola utilizamos un módulo (Mmain) y una clase (Alumno)
permite ingresar los siguientes datos Nombre, curso, seccion, numero de matricula, y tres parciales; parcial1,parcial2,parcial3, y muetra los siguientes datos: el promedio, total de los tres parciales, fecha de matricula y el nombre completo.

MODULO MMain
PUBLIC SUB Main()
'Instarciar Objetos
DIM matricula AS Alumno
DIM nom AS String
DIM ape AS String
DIM curs AS Integer
DIM secc AS String
DIM fecha2 AS Date
DIM parcial AS Integer
matricula = NEW Alumno
PRINT "<<<>>>"
PRINT "INGRESE LOS SIGUIENTES DATOS"
PRINT "Ingrese Nombre...>"
INPUT nom
PRINT "Ingrese Curso...>"
INPUT curs
PRINT "Ingrese Sección...>"
INPUT secc
PRINT "Ingrese Fecha Matricula...>"
INPUT fecha2
'PRINT fecha2
PRINT "Ingrese el Parcial 1...>"
INPUT parcial
matricula.ParcialUno(parcial)
PRINT "Ingrese el Parcial 2...>"
INPUT parcial
matricula.ParcialDos(parcial)
PRINT "Ingrese el Parcial 3...>"
INPUT parcial
matricula.ParcialTres(parcial)
PRINT "El Promedio es....>>>>", matricula.PromedioFinal()
PRINT "La Fecha de Matricula es....>>>>", matricula.fechama(fecha2)
matricula.PoneNombre(nom)
matricula.PoneApellido("Garcia")
PRINT "El Nombre completo es....>>>", matricula.NombreCompleto()
END
CLASE Alumno
PRIVATE Promedio AS Integer
PRIVATE FechaMatricula AS Date
PRIVATE Nombre AS String
PRIVATE Apellido AS String
PRIVATE parcial1 AS Single
PRIVATE parcial2 AS Single
PRIVATE parcial3 AS Single
PUBLIC SUB ParcialUno(numero AS Integer)
parcial1 = numero
END
PUBLIC SUB ParcialDos(numero AS Integer)
parcial2 = numero
END
PUBLIC SUB ParcialTres(numero AS Integer)
parcial3 = numero
END
PUBLIC FUNCTION PromedioFinal() AS Single
RETURN (parcial1 + parcial2 + parcial3) / 3
END
PUBLIC FUNCTION fechama(fecha AS Date) AS Date
FechaMatricula = fecha
RETURN FechaMatricula
END
PUBLIC SUB PoneNombre(cadena AS String)
Nombre = cadena
END
PUBLIC SUB PoneApellido(cadena AS String)
Apellido = cadena
END
PUBLIC FUNCTION NombreCompleto() AS String
RETURN Nombre & "" & Apellido
END

Código Número Mayor

MAYOR
Este programa permite seleccionar en orden los números mayor, menor, y medio, para esto ingresamos tres valores, Valor A,Valor B, Valor C. Utilizamos un modulo principal (MMain).

MODULO MMain
PUBLIC SUB Main()
DIM a, b, c AS Integer
PRINT "<<<>>>"
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

Código Hombre,Servicio

OBJETOS
En este programa utilizamos un modulo (Mmain) y dos clases Servicio y Hombre
despliega por pantalla la edad y nombre del mono, además permite ingresar el nombre y muestra la edad y nombre completo de la persona.

MODULO MMain
PUBLIC SUB Main()
'instanciar objetos
DIM mono AS Servivo
DIM persona AS Hombre
DIM no AS String
mono = NEW Servivo
mono.nacido(CDate("2/2/1992"))
mono.PonePatas(2)
PRINT "La edad del mono es..", mono.edad()
PRINT "Las patas del mono son..", mono.dicePatas()
persona = NEW Hombre
PRINT "Ingrese nombre..."
INPUT no
persona.PoneNombre(no)
persona.nacido(CDate("2/18/1969"))
persona.PoneApellido("Picapiedra")
PRINT "La edad de la persona es", persona.edad()
PRINT "El nombre completo es...", persona.NombreCompleto()
END
Servicio
PRIVATE patas AS Integer
PRIVATE nacimiento AS Integer
PUBLIC SUB nacido(fecha AS Integer)
nacimiento = Year(fecha)
END
PUBLIC SUB PonePatas(numero AS Integer)
patas = numero
END
PUBLIC FUNCTION edad() AS Integer
RETURN Year(Now) - nacimiento
END
PUBLIC FUNCTION dicePatas() AS Integer
RETURN patas
END
Hombre
INHERITS Servivo
PRIVATE Nombre AS String
PRIVATE Apellido AS String
PUBLIC SUB PoneNombre(cadena AS String)
Nombre = cadena
END
PUBLIC SUB PoneApellido(cadena AS String)
Apellido = cadena
END
PUBLIC FUNCTION NombreCompleto() AS String
RETURN Nombre & "" & Apellido
END

Código Factorial De Un Número

EL FACTORIAL DE UN NÚMERO
Este programa permite calcular el factorial de un numero, para ello debemos ingresar un valor . Solo utilizamos un modulo (Mmain).

MODULO MMain
PUBLIC SUB Main()
DIM f, i, l AS Integer
DIM nombre, res AS String
PRINT "<<<>>>"
PRINT "Ingrese un valor"
INPUT l
f = 1
FOR i = 2 TO l
f = f * i
NEXT
PRINT "El factorial del numero ingresado es !", f
END

Código Operaciones Basicas

OPERACIONES
En este programa utilizamos un formulario con 4 label, 3 TextBox, 6 Button, calcula las operaciones básicas, suma, resta, multiplicación, y división.

PUBLIC SUB Button1_Click()
TextBox3.Text = TextBox1.Text + TextBox2.Text
TextBox1.SetFocus
END
PUBLIC SUB Button3_Click()
ME.Close
END
PUBLIC SUB Button2_Click()
TextBox1.Clear
TextBox2.Clear
TextBox3.Clear
TextBox1.SetFocus
END
PUBLIC SUB TextBox1_KeyPress()
TextBox2.SetFocus
END
PUBLIC SUB Button5_Click()
TextBox3.Text = TextBox1.Text - TextBox2.Text
TextBox1.SetFocus
END
PUBLIC SUB Button4_Click()
TextBox3.Text = TextBox1.Text * TextBox2.Text
TextBox1.SetFocus
END
PUBLIC SUB Button6_Click()
TextBox3.Text = TextBox1.Text / TextBox2.Text
TextBox1.SetFocus
END

Código Productos

PRODUCTOS
En este programa calculamos el total de quintales, y el porcentaje de cada uno, para ello ingresamos cantidad de café, cacao, maíz. Solo utilizamos un modulo (MMain)

MODULO Mmain

PUBLIC SUB Main()
DIM A, B, C, S, PC, PC1, PM AS Integer
PRINT "<>>"
PRINT "Ingrese cantidad de cafe"
INPUT A
PRINT "Ingrese cantidad de cacao"
INPUT B
PRINT "Ingrese cantidad de maiz"
INPUT C
PRINT "El total de cafe es...", A
PRINT "El total de cacao es...", B
PRINT "El total de maiz es...", C
S = A + B + C
PRINT "El total de quintales es...", S
PRINT "EL PORCENTAJE DE CADA PRODUCTO ES"
PC = (S * A) / 100
PC1 = (S * B) / 100
PM = (S * C) / 100
PRINT "El porcentaje de cafe es...%", PC
PRINT "El porcentaje de cacao es...%", PC1
PRINT "El porcentaje de maiz es...%", PM
END

Código Promedio

PROMEDIO
Este programa calcula la suma, el promedio, la equivalencia en letras, y el resultado si aprueba o no la materia. Con tres notas, segun la siguiente tabla 10 sobresaliente,9-8 muy buena,7 buena, 6-1 insuficiente.
Para esto utilizamos dos modulos el principal (MMain) y otro Module1.

MODULO Mmain
PUBLIC SUB Main()
DIM cal1, cal2, cal3 AS Integer
PRINT "INGRESE NOTA 1:..."
INPUT cal1
PRINT " INGRESE NOTA 2:..."
INPUT cal2
PRINT " INGRESE NOTA 3:..."
INPUT cal3
PRINT "<<<>>>", Module1.SUM(cal1, cal2, cal3)
PRINT "<<<>>>", Module1.PROM(cal1, cal2, cal3)
PRINT "<<<>>>", Module1.EQUIVAL(cal1, cal2, cal3)
PRINT "RESULTADO", Module1.RESULTADO(cal1, cal2, cal3)
END
MODULE 1
PUBLIC FUNCTION SUM(p1 AS Integer, p2 AS Integer, p3 AS Integer) AS Integer
DIM s AS Integer
s = p1 + p2 + p3
RETURN s
END
PUBLIC FUNCTION PROM(p1 AS Integer, p2 AS Integer, p3 AS Integer) AS Integer
DIM prom AS Integer
prom = (p1 + p2 + p3) DIV 3
RETURN prom
END
PUBLIC FUNCTION EQUIVAL(p1 AS Integer, p2 AS Integer, p3 AS Integer) AS String
DIM equi AS Integer
DIM e AS String
equi = (p1 + p2 + p3) DIV 3
IF (equi <>
e = "insuificiente"
ELSE IF (equi = 7) THEN
e = "bueno"
ELSE IF (equi <>
e = "muy bueno"
ELSE
e = "sobresaliente"
END IF
RETURN e
END
PUBLIC FUNCTION RESULTADO(p1 AS Integer, p2 AS Integer, p3 AS Integer) AS String
DIM equi AS Integer
DIM e AS String
equi = (p1 + p2 + p3) DIV 3
IF (equi <>
e = "REPRUEBA"
ELSE IF (equi <>
e = "RECUPERACION"
ELSE
e = "APRUEBA"
END IF
RETURN e
END

Formulario Usuarios TIA

usuario
tiene 4 Label, 5 Button, 3 TextBox, 1GridView.

PUBLIC f AS Integer
PUBLIC au AS Integer
PUBLIC SUB Button2_Click()
IF TextBox3 = "" AND TextBox1 = "" AND TextBox2 = "" THEN
Message.Info("Ingrese datos...")
limpiar()
TextBox3.SetFocus
ELSE
TRY modulo.cn.Exec("insert into clave values( '" & Trim(TextBox3.Text) & "','" & Trim(TextBox1.Text) & "', '" & Trim(TextBox2.Text) & "') ")
IF ERROR THEN
Message.Error("Imposible Ingresar el usuario...")
ELSE
Message.Info("Usuario Ingresado...")
au = au + 1
' deshabilt()
ENDIF
modulo.rs = modulo.cn.Exec("select * from clave")
mostrar()
'limpiar()
deshabilt()
'ELSE
'Message.Info("Debe ingresar datos...")
ENDIF
END
PUBLIC SUB limpiar()
TextBox1.Clear
TextBox2.Clear
TextBox3.Clear
END
PUBLIC SUB mostrar()
modulo.rs.MoveFirst
IF modulo.rs.Count > 0 THEN
Grid1.Columns.Count = 3
Grid1.Rows.Count = modulo.rs.Count + 1
Grid1.Columns[0].Width = 50
Grid1.Columns[1].Width = 250
Grid1.Columns[2].Width = 250
Grid1[0, 0].Text = "Idclave"
Grid1[0, 1].Text = "Usuario"
Grid1[0, 2].Text = "Password"
f = 1
modulo.rs.MoveFirst
DO WHILE modulo.rs.Available
Grid1[f, 0].Text = modulo.rs["idclave"]
Grid1[f, 1].Text = modulo.rs["usuario"]
Grid1[f, 2].Text = modulo.rs["contrasenia"]
f = f + 1
modulo.rs.MoveNext()
LOOP
ENDIF
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
' habilit()
Button3.SetFocus
ENDIF
ENDIF
END
PUBLIC SUB deshabilt()
Button2.Enabled = FALSE
Button3.Enabled = FALSE
Button4.Enabled = FALSE
Button5.Enabled = FALSE
TextBox1.Enabled = FALSE
TextBox2.Enabled = FALSE
TextBox3.Enabled = FALSE
END
PUBLIC SUB habilit()
Button2.Enabled = TRUE
Button3.Enabled = TRUE
Button4.Enabled = TRUE
Button5.Enabled = TRUE
TextBox1.Enabled = TRUE
TextBox2.Enabled = TRUE
TextBox3.Enabled = TRUE
END
PUBLIC SUB Form_Open()
ME.Center
modulo.conectar
modulo.rs = modulo.cn.Exec("select * from clave")
mostrar()
'deshabilitar()
' deshabilt()
END
PUBLIC SUB Button1_Click()
' TextBox1.Clear
' TextBox2.Clear
limpiar()
habilit()
TextBox3.setfocus
END
PUBLIC SUB Button4_Click()
SELECT Message.Question("Desea eliminar el Usuario", "Si", "No")
CASE 1
TRY Modulo.cn.Exec("Delete from clave where usuario='" & Trim(UCase(TextBox1.Text)) & "'")
IF ERROR THEN
Message.Error("Imposible de borrar el usuario")
ELSE
modulo.rs = Modulo.cn.Exec("select * from clave")
mostrar()
END IF
CASE 2
Message.Info("Usuario no eliminado")
CASE 3
END SELECT
limpiar()
TextBox3.SetFocus
END
PUBLIC SUB Button5_Click()
DIM ban AS Integer
Modulo.rs = Modulo.cn.Exec("select * from clave")
DO WHILE Modulo.rs.Available
IF modulo.rs["idclave"] = Trim(UCase(TextBox3.Text)) THEN
Modulo.rs = Modulo.cn.Exec("select * from clave where idclave = '" & Trim(UCase(TextBox3.Text)) & "'")
TextBox1.Text = Modulo.rs["usuario"]
TextBox2.Text = Modulo.rs["contrasenia"]
'ValueBox1.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 TextBox3_KeyPress()
IF Key.Code = 65293 THEN
IF TextBox3.Text = "" THEN
Message.Info("Ingrese Nombre de Usuario...")
TextBox3.SetFocus
ELSE
TextBox1.SetFocus
ENDIF
ENDIF
END
PUBLIC SUB menu_Click()
ME.Close
END
PUBLIC SUB Button3_Click()
TRY Modulo.cn.Exec("update clave set idclave='" & Trim(UCase(TextBox3.Text)) & "',usuario='" & Trim(UCase(TextBox1.Text)) & "',contrasenia='" & Trim(UCase(TextBox2.Text)) & "' where=textbox3.text ")
IF ERROR THEN
Message.Error("Imposible actualizar el registro")
ELSE
Message.Info("Registro actualizado")
END IF
mostrar()
'LIMPIAR
END

Gambas

menuprincipal


PUBLIC SUB inventario_Click()
FMain.Show
END
PUBLIC SUB salir_Click()
ME.Close
END
PUBLIC SUB usuarios_Click()
usuario.Show
END
PUBLIC SUB Form_Open()
ME.Center
modulo.conectar
END
protector
Este formulario tiene 1 DrawingArea, 1 Button, y un timer.

PUBLIC x AS Integer
PUBLIC y AS Integer
PUBLIC r AS Integer
PUBLIC g AS Integer
PUBLIC b AS Integer
PUBLIC SUB Button1_Click()
Timer1.Enabled = TRUE
END
PUBLIC SUB Timer1_Timer()
x = Int(Rnd * 800)
y = Int(Rnd * 600)
r = Int(Rnd * 255)
g = Int(Rnd * 255)
b = Int(Rnd * 255)
Draw.Begin(area1)
Draw.FillColor = Color.Red
Draw.FillColor = Color.RGB(r, g, b)
Draw.FillStyle = Fill.Solid
Draw.Circle(x, y, 80)
Draw.Circle(200, 200, 80)
Draw.Rect(100, 100, 100, 50)
Draw.End
END

Progamacion en Gambas

TIA
En este programa utilizamos un modulo (Modulo), y 5 formularios, acceso, inventario (Fmain), menuprincipal,protector, usuario, Y una base de datos con dos tablas, clave y producto.
Modulo
PUBLIC cn AS NEW connection
PUBLIC rs AS Result
PUBLIC SUB conectar()

'WITH Modulo.cn
cn.CLOSE
cn.type = "mysql"
cn.host = "localhost" ' 192.168.1.201
cn.login = "root"
cn.port = "3306"
cn.password = "root"
cn.name = "tia"
'evalua y devuelve errores
TRY cn.OPEN
IF ERROR THEN
Message("Error al abrir base de datos")
ELSE
Message("Ingresando a base de datos")
ENDIF

END
acceso
Tiene 3 Label , 2 textbox, y 2 button

PUBLIC c AS Integer
PUBLIC n AS String

PUBLIC SUB Form_Open()

ME.Center
modulo.conectar
' modulo.rs = modulo.cn.Exec("select * from clave")
n = "Administrador"

END

PUBLIC SUB Button1_Click()
DIM ban AS Integer
modulo.rs = modulo.cn.Exec("select * from clave")

DO WHILE modulo.rs.Available
n = modulo.rs["usuario"]
IF modulo.rs["usuario"] = Trim(TextBox2.Text) AND modulo.rs["contrasenia"] = Trim(TextBox1.Text) THEN
modulo.rs = modulo.cn.Exec("select * from clave where usuario = '" & Trim(TextBox1.Text) & "'")
Message.Info("Bienvenidos. " & n, "Aceptar")
ME.Hide
menuprincipal.Show
ban = 1
ENDIF
modulo.rs.MoveNext()
LOOP
IF ban = 0 THEN
c = c + 1
IF c = 3 THEN
Message.Warning("Error, El sistema debe cerrarse por seguridad.")
ME.Close
ELSE
limpiar()
TextBox1.SetFocus
Message.Error("Usuario no existe, intente de nuevo...", "Aceptar")
ENDIF
END IF

END
PUBLIC SUB limpiar()

Button1.Enabled = FALSE
Button2.Enabled = FALSE
TextBox1.Clear
TextBox2.Clear
TextBox2.Enabled = FALSE
TextBox1.SetFocus
END
INVENTARIO (Fmain)
Tiene 5 label, 3 texbox, 1 ValueBox, 6 button, 1 TabStrip, 1 GridView

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 Button6_Click()

ME.Close

END

PUBLIC SUB Button3_Click()

TRY Modulo.cn.Exec("insert into producto values('" & Trim(UCase(TextBox1.Text)) & "','" & Trim(UCase(TextBox2.Text)) & "','" & (TextBox3.Text) & "','" & (ValueBox1.Text) & "');")
IF ERROR THEN
Message.Error("Imposible presentar el registro")
ELSE
Message.Info("registro insertado")
ENDIF
Modulo.rs = Modulo.cn.Exec("Select * from producto")
mostrar()
desabilitar()
END
PUBLIC SUB desabilitar()
TextBox1.Enabled = FALSE
TextBox2.Enabled = FALSE
TextBox3.Enabled = FALSE
ValueBox1.Enabled = FALSE
END
PUBLIC SUB mostrar()
Modulo.rs.MoveFirst
IF Modulo.rs.count > 0 THEN
GridView1.columns.count = 4
GridView1.Rows.Count = Modulo.rs.count + 1
GridView1.columns[0].width = 60
GridView1.columns[1].width = 180
GridView1.columns[2].width = 80
GridView1.columns[3].width = 80
GridView1[0, 0].Text = "codigo"
GridView1[0, 1].Text = "nombre"
GridView1[0, 2].Text = "cantidad"
GridView1[0, 3].Text = "precio unitatrio"
fil = 1
Modulo.rs.MoveFirst
DO WHILE Modulo.rs.Available

GridView1[fil, 0].Text = Modulo.rs["codigo"]
GridView1[fil, 1].Text = Modulo.rs["nombre"]
GridView1[fil, 2].Text = Modulo.rs["cantidad"]
GridView1[fil, 3].Text = Modulo.rs["precio"]
fil = fil + 1
Modulo.rs.MoveNext()
LOOP
ENDIF

END


PUBLIC SUB Button4_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()
TextBox1.SetFocus
END

PUBLIC SUB Button5_Click()

TRY Modulo.cn.Exec("update producto set nombre='" & Trim(UCase(TextBox2.Text)) & "',precio='" & Trim(UCase(TextBox3.Text)) & "',cantidad='" & Trim(UCase(ValueBox1.Text)) & "' where=textbox1.text ")
IF ERROR THEN
Message.Error("Imposible actualizar el registro")
ELSE
Message.Info("Registro actualizado")
END IF
mostrar
'LIMPIAR

END

PUBLIC SUB Button2_Click()

TextBox1.Clear
TextBox2.Clear
TextBox3.Clear
TextBox3.Text = 0
ValueBox1.Clear
abilitar()
TextBox1.SetFocus

END
PUBLIC SUB abilitar()
TextBox1.Enabled = TRUE
TextBox2.Enabled = TRUE
TextBox3.Enabled = TRUE
ValueBox1.Enabled = TRUE
END

PUBLIC SUB Button1_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"]
ValueBox1.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
ValueBox1.Clear

END

PUBLIC SUB GridView1_DblClick()

IF GridView1.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(GridView1.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
GridView1.Columns.Width = 100

END
PUBLIC SUB TextBox1_KeyPress()

IF Key.Code = 65293 THEN
IF TextBox1.Text = "" THEN
Message.Info("Ingrese codigo de producto")
TextBox1.SetFocus
ELSE
TextBox2.SetFocus
ENDIF
ENDIF
END

PUBLIC SUB TextBox2_KeyPress()

IF Key.Code = 65293 THEN
IF TextBox1.Text = "" THEN
Message.Info("Ingrese codigo de producto")
TextBox2.SetFocus
ELSE
TextBox3.SetFocus
ENDIF
ENDIF
END