miércoles, 4 de noviembre de 2009

EJERCICIO CON EJEMLO ALEATORIOS

EJERCICIO UTILIZANDO EL DRAWING AREA DISEÑO:



CODIGO DEL EJERCICIO

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
' Draw.Begin(area1)
' Draw.FillColor = Color.Red
'Draw.FillStyle = Fill.Solid
' Draw.Circle(200, 200, 80)
' Draw.Rect(80, 80, 80, 40)
' Draw.End
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.Rect(100 + y, 100 + x, 100, 50)
Draw.End
END

PUBLIC SUB Button2_Click()
Timer2.Enabled = TRUE
' x = Int(Rnd * 800)
'y = Int(Rnd * 600)
' Draw.Begin(area1)
'Draw.FillColor = Color.Red
'Draw.FillStyle = Fill.Solid

' Draw.Ellipse(x, y, 80)
'Draw.Picture(100 + y, 100 + x, 100, 50)
'Draw.End
END

PUBLIC SUB Timer2_Timer()
x = Int(Rnd * 800)
y = Int(Rnd * 600)
Draw.Begin(area1)
Draw.FillColor = Color.Red
Draw.FillStyle = Fill.Solid
Draw.Circle(x, 20, 80)
'Draw.Picture(100 + y, 100 + x, 100, 50)
Draw.End
END

CODIGO

EMPRESAS TIA (EJERCICIO REALIZADO EN APLICACION CONSOLA, EN LENGUAJE ORIENTADO A OBJETOS.

PUBLIC cn AS NEW Connection
PUBLIC rs AS result
PUBLIC SUB conectar()
'with modulo.cn
cn.CLOSE
cn.type = "mysql"
cn.host = "localhost"
cn.login = "root"
cn.Port = "3306"
cn.Password = "root"
cn.name = "tia"
TRY cn.OPEN
IF ERROR THEN
Message("Error al Abrir Base de Datos")
ELSE
Message("Ingresandoo a Base de Datos")
ENDIF
END

ESTE ES EL DISEÑO DEL FORMULARIO DE ACCESSO



ESTA ES LA CODIFICACION

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
modulo.rs = modulo.cn.Exec("select * from claves")
DO WHILE modulo.rs.Available
n = modulo.rs["usuario"]
IF modulo.rs["usuario"] = Trim(TextBox1.Text) AND modulo.rs["contrasena"] = Trim(TextBox2.Text) THEN
modulo.rs = modulo.cn.Exec("select * from claves where usuario = '" & Trim(TextBox1.Text) & "'")
Message.Info("Bienvenido al sistema Sr(a). " & 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("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 limpiar()
Button1.Enabled = FALSE
Button2.Enabled = FALSE
TextBox1.Clear
TextBox2.Clear
TextBox2.Enabled = FALSE
TextBox1.SetFocus
END


PUBLIC SUB Button2_Click()
limpiar()
END


ESTE ES EL DISEÑO DEL FORMULARIO PARA EL MENU




'Y ESTA ES LA CODIFICACION
PUBLIC SUB Inventario_Click()
FMain.Show
END

PUBLIC SUB Salir_Click()
QUIT
END

PUBLIC SUB Usuarios_Click()
newusuario.Show
END


ESTE ES EL DISEÑO DEL FORMULARIO PARA REALIZAR LAS COMPRAS


'CODIFICACION REALIZADA EN EL MMain



'CODIGO PARA REALIZAR LAS COMPRAS

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()
limpiar
END

'BOTON GUARDAR
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 insertar el registro")
ELSE
Message.Info("Registro insertado")
limpiar
END IF
Modulo.rs = Modulo.cn.Exec("Select * from producto")
mostrar()
END

PUBLIC SUB mostrar()
Modulo.rs.MoveFirst
IF Modulo.rs.Count > 0 THEN
GridView1.Columns.Count = 4
GridView1.Rows.Count = Modulo.rs.Count + 2
GridView1.Columns[1].Width = 30
GridView1.Columns[1].Width = 30
GridView1[0, 0].Text = "Codigo"
GridView1[0, 1].Text = "Nombre"
GridView1[0, 2].Text = "Precio Unitario"
GridView1[0, 3].Text = "Cantidad"
fil = 1
Modulo.rs.MoveFirst
'con = Modulo.rs.Count
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["precio"]
GridView1[fil, 3].Text = Modulo.rs["cantidad"]
fil = fil + 1
Modulo.rs.MoveNext()
LOOP
ENDIF
END

'ELIMINAR COMPLETADO
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; Ingrese numero de Registro....! ")
limpiar
ELSE
Modulo.rs = Modulo.cn.Exec("select * from producto")
mostrar()

END IF
CASE 2
Message.Info("Registro no eliminado")
limpiar
CASE 3
END SELECT
limpiar()
END

'BUSCAR COMPLETADO
PUBLIC SUB Button6_Click()
DIM ban AS Integer
Button4.Enabled = TRUE
'Button5.Enabled = TRUE
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; Ingrese Registro....! ")
limpiar()
END IF
END

'MODULO LIMPIAR COMPLETADO
PUBLIC SUB limpiar()
TextBox1.Clear
TextBox2.Clear
TextBox3.Clear
TextBox3.Text = 0
ValueBox1.Clear
TextBox1.SetFocus
END


'MODIFICAR COMPLETADO
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 ")
TRY Modulo.cn.Exec("update producto set nombre='" & Trim(TextBox2.Text) & "',precio='" & Trim(TextBox3.Text) & "',cantidad='" & Trim(ValueBox1.Text) & "' where=textbox1.text ")
IF ERROR THEN
Message.Error("Imposible actualizar el registro")
ELSE
Message.Info("Registro actualizado")
END IF
mostrar
LIMPIAR
END



'finalizar
PUBLIC SUB TextBox2_KeyPress()

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

PUBLIC SUB TextBox1_KeyPress()

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



'LIMPIAR COMPLETO
PUBLIC SUB Button2_Click()
limpiar()
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 Button1_Click()
'Message("finalizando")
FMain.Hide

menuprincipal.Show

'QUIT

END


PUBLIC SUB TextBox3_KeyPress()
IF Key.Code = 65293 THEN
IF TextBox3.Text = "" THEN
Message.Info("Ingrese nombre del producto..")
TextBox3.SetFocus
ELSE
ValueBox1.SetFocus
ENDIF
ENDIF
END



'ESTE ES EL DISEÑO PARA EL FORMULARIO CREACION DE USUARIOS



ESTE ES EL CODIGO DEL FORMULARIO COMPRAS DE USUARIO

' Gambas class file
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 claves")
mostrar()
limpiar
END

PUBLIC SUB Button1_Click()
limpiar
END

'BOTON GUARDAR
PUBLIC SUB Button2_Click()
DIM id AS Integer

'Modulo.rs = Modulo.cn.Exec("select * from claves")
'DO WHILE Modulo.rs.Available

'IF modulo.rs["idclave"] = Trim(UCase(TextBox1.Text)) THEN
'Modulo.rs = Modulo.cn.Exec("select * from claves where idclave = '" & Trim(UCase(TextBox1.Text)) & "'")
'id = modulo.rs

IF id = TextBox1.Text THEN
Message("ingrese un idcliente que no exista")
limpiar
ELSE
TRY Modulo.cn.Exec("insert into claves values('" & Trim(TextBox1.Text) & "','" & Trim(TextBox2.Text) & "','" & Trim(TextBox3.Text) & "');")

IF ERROR THEN
Message.Error("Imposible insertar el registro")
ELSE
Message.Info("Registro insertado")
limpiar
END IF
Modulo.rs = Modulo.cn.Exec("Select * from claves")
mostrar()
ENDIF
'ban = 1
'ENDIF
'MODULO.rs.MoveNext()
'LOOP

END

PUBLIC SUB limpiar()
TextBox1.Clear
TextBox2.Clear
TextBox3.Clear
TextBox1.Enabled = TRUE
TextBox2.Enabled = TRUE
TextBox3.Enabled = TRUE
Button2.Enabled = FALSE
Button4.Enabled = FALSE
Button7.Enabled = FALSE
TextBox1.SetFocus
END


PUBLIC SUB mostrar()
Modulo.rs.MoveFirst
IF Modulo.rs.Count > 0 THEN
GridView1.Columns.Count = 3
GridView1.Rows.Count = Modulo.rs.Count + 2
GridView1.Columns[1].Width = 30
GridView1.Columns[1].Width = 30
GridView1[0, 0].Text = "idclave"
GridView1[0, 1].Text = "usuario"
GridView1[0, 2].Text = "contrasena"
fil = 1
Modulo.rs.MoveFirst
'con = Modulo.rs.Count
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

'eliminar
PUBLIC SUB Button4_Click()
SELECT Message.Question("Desea eliminar el usuario ", "Si", "No")
CASE 1
TRY Modulo.cn.Exec("Delete from claves where usuario='" & Trim(UCase(TextBox2.Text)) & "'")
IF ERROR THEN
Message.Error("Imposible borrar el registro; Ingrese nombre del usuario....! ")
limpiar
ELSE
Modulo.rs = Modulo.cn.Exec("select * from claves")
mostrar()
END IF
CASE 2
Message.Info("Registro no eliminado")
limpiar
CASE 3
END SELECT
limpiar()
Button2.Enabled = FALSE
Button4.Enabled = FALSE
Button7.Enabled = FALSE
END

'buscar
PUBLIC SUB Button5_Click()
DIM ban AS Integer
GridView1.Visible = TRUE
Button7.Enabled = TRUE
Button4.Enabled = TRUE
Message("Ingrese Id de Usuario..")
TextBox1.SetFocus
Modulo.rs = Modulo.cn.Exec("select * from claves")
DO WHILE Modulo.rs.Available
IF modulo.rs["idclave"] = Trim(UCase(TextBox1.Text)) THEN
Modulo.rs = Modulo.cn.Exec("select * from claves where idclave = '" & Trim(UCase(TextBox1.Text)) & "'")
TextBox1.Text = Modulo.rs["idclave"]
TextBox2.Text = Modulo.rs["usuario"]
TextBox3.Text = Modulo.rs["contrasena"]
TextBox1.Enabled = FALSE
TextBox2.Enabled = FALSE
TextBox3.Enabled = FALSE
'TextBox3.Text = Modulo.rs["precio"]
ban = 1
ENDIF
MODULO.rs.MoveNext()
LOOP
IF ban = 0 THEN
Message.Error("Registro Invalido; Ingrese Registro....! ")
limpiar()
END IF
END

PUBLIC SUB Button6_Click()
QUIT
END

PUBLIC SUB TextBox2_KeyPress()
'DIM t AS Integer
't = Len(TextBox2.Text)

' IF t < 6 THEN
'IF TextBox2_Change = "32" THEN
Button2.Enabled = TRUE
'Button2.SetFocus
END

PUBLIC SUB TextBox1_KeyPress()
'IF TextBox1.Text <> "" THEN
'TextBox2.SetFocus
'ELSE
'message.Info(" ingrese registrio ")
'TextBox1.Text = ""
'TextBox1.SetFocus
'ENDIF
END

PUBLIC SUB Button7_Click()
Button4.Enabled = TRUE
TextBox1.Enabled = TRUE
TextBox2.Enabled = TRUE
TextBox3.Enabled = TRUE
END

MUESTRA EL FACTORIAL DE UN NUMERO Y ADEMAS UN NOMBRE INGRESADO LETRA POR LETRA UTILIZANDO LA INSTRUCCION LEN(PARA EXTRAER EL TAMAÑO DE LA CADENA Y REA

'MUESTRA EL FACTORIAL DE UN NUMERO
PUBLIC SUB Main()
DIM nombre, res AS String
DIM f, l, i AS Integer
f = 1
FOR i = 2 TO 5
f = f * i
NEXT
PRINT "el factorial de 5 es ", f

'MUESTRA EL NOMBRE INGRESADO LETRA POR LETRA
PRINT "Ingrese nombre "
INPUT nombre
l = Len(nombre)
PRINT "\n"
PRINT "El resultado es:"
FOR i = 1 TO l
res = Mid(nombre, i, 1)
PRINT res
NEXT
END

INGRESA TRES NUMEROS Y MUESTRA EL VALOR MAYOR, EL INTERMEDIO Y EL VALOR MENOR DE LOS VALORES INGRESADOS.

EJERCICIO PARA DETERMINAR DE TRES VALORES INGRESADOS EL MAYOR, EL INTERMEDIO Y EL MENOR.

PUBLIC SUB Main()

DIM a, b, c AS Integer
INPUT a
PRINT "Ingrese el Primer Valor", a
INPUT b
PRINT "Ingrese el Segundo Valor", b
INPUT c
PRINT "Ingrese el Tercer Valor", c


IF (a > b) AND (a > c) THEN
IF b > c THEN
PRINT "El mayor valor ingresado es: ", a
PRINT "El intermedio valor ingresado es: ", b
PRINT "El menor valor ingresado es: ", c
ELSE
PRINT "El mayor valor ingresado es: ", a
PRINT "El intermedio valor ingresado es: ", c
PRINT "El menor valor ingresado es: ", b
ENDIF
ENDIF


IF b > a AND b > c THEN
IF a > c THEN
PRINT "El mayor es: ", b
PRINT "El intermedio es: ", a
PRINT "El menor es: ", c
ELSE
PRINT "El mayor valor ingresado es: ", b
PRINT "El intermedio valor ingresado es: ", c
PRINT "El menor valor ingresado es: ", a
ENDIF
ENDIF


IF c > b AND c > a THEN
IF a > b THEN
PRINT "El mayor valor ingresado es: ", c
PRINT "El intermedio valor ingresado es: ", a
PRINT "El menor valor ingresado es: ", b
ELSE
PRINT "El mayor : ", c
PRINT "El intermedio es: ", b
PRINT "El menor es: ", a
ENDIF
ENDIF
END

EJERCICIO DE EJEMPLO DE MATRICULA

'EJEMPLO DE MATRICULA BASADO EN FUNCIONES

PUBLIC SUB Main()
DIM matr AS matricula
DIM nom AS String
DIM nmatri AS Integer
DIM parc1, parc2, parc3 AS Integer
matr = NEW matricula
'mat.matri(Now)

PRINT "La fecha de matricula es.....:", matr.matri()
PRINT "Ingrese nombre..."
INPUT nom
matr.PoneNombre(nom)

PRINT "Ingrese numero de matricula..:"
INPUT nmatri
matr.PoneApellido("MOREIRA")
'PRINT "la fecha de matricula es..", mat.Ponefecha("18/12/1992")
matr.PoneCurso("5 B Sistemas")
matr.PoneSeccion("Nocturno")

' FUNCIONES...."
PRINT "El nombre completo es....", matr.NombreCompleto()
PRINT "Curso : ", matr.Cursoactual()
PRINT "Seccion : ", matr.Seccionactual()

'INGRESOS
PRINT "Ingrese primer parcial...."
INPUT parc1
matr.Poneparcial1(parc1)

PRINT "Ingrese segundo parcial...."
INPUT parc2
matr.Poneparcial2(parc2)

PRINT "Ingrese tercer parcial...."
INPUT parc3
matr.Poneparcial3(parc3)

PRINT "El promedio es...", matr.promedio()
matr.equiv(parc1, parc2, parc3)
END

FUNCIONES DEL EJERCICIO PARA RECIBIR LOS VALORES INGRESADOS Y REALIZAR LAS OPERACIONES

PRIVATE Nombre AS String
PRIVATE Apellido AS String
PRIVATE Curso AS String
PRIVATE Seccion AS String
PRIVATE Fmatricula AS Integer
PRIVATE parcial1 AS Single
PRIVATE parcial2 AS Single
PRIVATE parcial3 AS Single

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

PUBLIC SUB Ponefecha(fecha AS Date)
Fmatricula = Year(fecha)
END

PUBLIC FUNCTION matri() AS Integer
RETURN Year(Now)
END

PUBLIC SUB PoneCurso(cadena AS String)
Curso = cadena
END

PUBLIC FUNCTION Cursoactual() AS String
RETURN Curso
END

PUBLIC SUB PoneSeccion(cadena AS String)
Seccion = cadena
END

PUBLIC FUNCTION Seccionactual() AS String
RETURN Seccion
END

PUBLIC SUB Poneparcial1(numero AS Integer)
parcial1 = numero
END

PUBLIC SUB Poneparcial2(numero AS Integer)
parcial2 = numero
END

PUBLIC SUB Poneparcial3(numero AS Integer)
parcial3 = numero
END

PUBLIC FUNCTION promedio() AS Single
RETURN (parcial1 + parcial2 + parcial3) / 3
END

PUBLIC FUNCTION equiv(parcial1 AS Integer, parcial2 AS Integer, parcial3 AS Integer) AS Integer
DIM tp AS Integer
PRINT "La Equivalencia es : "
tp = (parcial1 + parcial2 + parcial3) / 3
IF (tp > 0) AND (tp < 7) OR (tp = 0) THEN
PRINT "Insuficiente"
ELSE
IF tp = 7 THEN
PRINT "Buena"
ELSE
IF (tp = 8) OR (tp = 9) THEN
PRINT "Muy buena"
ELSE
IF tp = 10 THEN
PRINT "Sobresaliente"
ENDIF
ENDIF
ENDIF
ENDIF
END
PUBLIC SUB Main()
DIM a, b AS Integer
PRINT "Valor 1: "
INPUT a
PRINT "Valor 2: "
INPUT b
PRINT "La suma de los valores es :", opera(a, b)
PRINT "La resta de los valores es :", resta(a, b)
PRINT "La multiplicacion de los valores es :", multi(a, b)
PRINT "La division de los valores es :", divi(a, b)
END

ESTAS SON LAS FUNCIONES PARA QUE RECIBEN LOS VALORES INGRESADOS LOS TOMA Y CADA FUNCION DEVUELVE LOS VALORES CORRESPONDIENTE DE LA SUMA, RESTA, MULTIPLICACION, DIVISION......

PUBLIC FUNCTION opera(v1 AS Integer, v2 AS Integer) AS Integer
DIM su AS Integer
su = v1 + v2
RETURN su
END

PUBLIC FUNCTION resta(v1 AS Integer, v2 AS Integer) AS Integer
DIM re AS Integer
re = v1 - v2
RETURN re
END

PUBLIC FUNCTION multi(v1 AS Integer, v2 AS Integer) AS Integer
DIM mu AS Integer
mu = v1 * v2
RETURN mu
END

PUBLIC FUNCTION divi(v1 AS Integer, v2 AS Integer) AS Single
DIM di AS Single
di = v1 / v2
RETURN di
END

AL EJECUTAR Y INGRESAR DATOS TE DARA LOS SIGUIENTES RESULTADOS

Valor 1:
2
Valor 2:
5
La suma de los valores es : 7
La resta de los valores es : -3
La multiplicacion de los valores es : 10
La division de los valores es : 0,40000000596

PORCENTAJE DE PRODUCTOS DE EXPORTACION

ESTE EJERCICIO PERMITE VISUALIZAR EL TOTAL DE QUINTALES INGRESADOS ENTRE CAFE, CACAO Y MAIZ ADEMAS EL PORCENTAJE DE CADA UNO DE ELLOS

' El Ecuador Exporta cafe, cacao y maiz en qq, Encontrar el Total de Quintales Exportados y el
porcentaje de cada producto exportado
PUBLIC SUB Main()
DIM c, cc, m, s, p1, p2, p3 AS Integer
PRINT "Ingrese Quintales de Cafe ..... :", c
INPUT c
PRINT "Ingrese Quintales de Cacao .... :", cc
INPUT cc
PRINT "Ingrese Quintales de Maiz ..... :", m
INPUT m

'INPUT c, cc, m
s = c + cc + m
p1 = (c * 100) / s
p2 = (cc * 100) / s
p3 = (m * 100) / s
PRINT "El total de quintales es ... : " & Str(s) & " entre cafe, cacao y maiz"
PRINT "El porcentaje de cafe es .... : " & Str(p1) & ""
PRINT "El porcentaje de cacao es ... : " & Str(p2) & ""
PRINT "El porcentaje de Maiz es .... : " & Str(p3) & ""
END

PROMEDIO Y EQUIVALENCIA

ESTE EJECICIO PERMITE EL CALCULO DE PROMEDIO DE TRES NOTAS INGRESADAS ADEMAS LA EQUIVALENCIA DE CADA PROMEDIO ENCONTRADO: AÑO APROBADO O ARRASTRE. UTILIZANDO LLAMADA A CADA FUNCION MODULO1.SUMA Y MODULO1.PROME PARA LA REALIZACION DE LAS OPERACIONES:

CODIFICACION EN EL MMain.


' Gambas module file
' Ingresar 3 (notas) parciales calcular la suma y el promedio, si aprueba, o se queda a recuperacion o no aprueba la materia
'ademas la equivalencia segun la siguiente: 10 sobresaliente, 9-8 muy buena, 7 buena, 6-1 insuficiente

PUBLIC SUB Main()
DIM p1, p2, p3, sum AS Integer
PRINT "Ingrese NOta 1 :"
INPUT p1
PRINT "Ingrese NOta 2 :"
INPUT p2
PRINT "Ingrese NOta 3 :"
INPUT p3

PRINT "suma ", Module1.suma(p1, p2, p3)
PRINT "Promedio", Module1.prome(p1, p2, p3)
PRINT "\n"
Module1.equiv(p1, p2, p3)
PRINT "\n"
Module1.obser(p1, p2, p3)

END

DANDO CLIC DERECHO EN MMain ESCOJEMOS MODULO1 PARA CREAR LAS FUNCIONES PARA CADA LLAMADA

'FUNCION SUMA OBIAMENTE PARA REALIZAR LA SUMA
PUBLIC FUNCTION suma(v1 AS Integer, v2 AS Integer, v3 AS Integer) AS Integer
DIM res AS Integer
res = v1 + v2 + v3
RETURN res
END

'FUNCION PROMEDIO PARA CALCULAR EL PROMEDIO
PUBLIC FUNCTION prome(v1 AS Integer, v2 AS Integer, v3 AS Integer) AS Single
DIM pr AS Single
pr = (v1 + v2 + v3) / 3
RETURN pr
END

'FUNCION EQUIVALENCIA PARA DAR A CONOCER LA NOTA
PUBLIC FUNCTION equiv(v1 AS Integer, v2 AS Integer, v3 AS Integer) AS Integer
DIM tp AS Integer
PRINT "La Equivalencia es : "
tp = (v1 + v2 + v3) / 3
IF (tp > 0) AND (tp < 7) OR (tp = 0) THEN
PRINT "Insuficiente"
ELSE
IF tp = 7 THEN
PRINT "Buena"
ELSE
IF (tp = 8) OR (tp = 9) THEN
PRINT "Muy buena"
ELSE
IF tp = 10 THEN
PRINT "Sobresaliente"
ENDIF
ENDIF
ENDIF
ENDIF
END

'FUNCION OBSERVACION SIRVE PARA SABER SI APRUEVA O SE QUEDA CON ARRASTRE.
PUBLIC FUNCTION obser(v1 AS Integer, v2 AS Integer, v3 AS Integer) AS Integer
DIM totp AS Integer
PRINT "Observacion :"
totp = (v1 + v2 + v3) / 3
IF (totp > 6) AND (totp < 11) THEN
PRINT " AÑO APROBADO"
ELSE
IF (totp < 7) AND (totp > 0) OR (totp = 0) THEN
PRINT "ARASTRE"
ENDIF
ENDIF
END

CALCULADORA

ESTE EJERCICIO TE PERMITE MOSTRAR EL FORMATO DE UNA CALCULADORA COMPLETA
Y LO MÁS IMPORTANTE PODRAS CONOCER Y APRENDER L CODIGO PARA CONVERTIR UN NUMERO A OPTAL, HEXADECIMAL Y OPERACIONES COMO SUMA , RESTA, MULTIPLICACION, DIVICION ADEMAS SENO (SIN), COSENO (COS), Y TANGENTE(TAN).



OJO ADEMAS CON APOSTROFE ESTA INDICANDO PARA QUE SIRVE CADA CODIFICACION:

' Gambas class file
PUBLIC ban AS Integer
PUBLIC aux1 AS Integer
PUBLIC aux2 AS Integer

PUBLIC SUB Button16_Click()
ME.Close
END

'ASIGNACION DE NUMEROS A LOS BUTTON
PUBLIC SUB Button1_Click()
VISOR.Text = VISOR.Text & "1"
END

PUBLIC SUB Button2_Click()
VISOR.Text = VISOR.Text & "2"
END

PUBLIC SUB Button3_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 Button7_Click()
VISOR.Text = VISOR.Text & "7"
END

PUBLIC SUB Button8_Click()
VISOR.Text = VISOR.Text & "8"
END

PUBLIC SUB Button9_Click()
VISOR.Text = VISOR.Text & "9"
END

PUBLIC SUB Button10_Click()
VISOR.Text = VISOR.Text & "0"
END

PUBLIC SUB Button11_Click()
VISOR.Text = VISOR.Text & "."
END

PUBLIC SUB Button17_Click()
VISOR.Clear
END

'suma
PUBLIC SUB Button12_Click()
ban = 1
IF VISOR.Text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF
VISOR.Clear
END

'resta
PUBLIC SUB Button13_Click()
ban = 2
IF VISOR.text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF
VISOR.Clear
END

'multiplicacion
PUBLIC SUB Button14_Click()
ban = 3
IF VISOR.Text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF
VISOR.Clear
END

'Division
PUBLIC SUB Button15_Click()
ban = 4
IF VISOR.Text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF
VISOR.Clear
END

'x2
PUBLIC SUB Button19_Click()
ban = 5
IF VISOR.Text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF
END

'Igual
PUBLIC SUB Button18_Click()
IF VISOR.Text <> 0 THEN
aux2 = VISOR.Text
ELSE
aux2 = 0
ENDIF
VISOR.Text = operaciones(ban, aux1, aux2)
END

'FUNCIONES PARA LAS OPERACIONES DE LA CALCULADORA
PUBLIC FUNCTION operaciones(opera AS Float, v1 AS Float, v2 AS Float) AS Float
DIM respuesta AS Float
SELECT CASE opera
CASE 1
respuesta = v1 + v2
CASE 2
respuesta = v1 - v2
CASE 3
respuesta = v1 * v2
CASE 4
respuesta = v1 / v2
CASE 5
respuesta = v1 * v1
'x3
CASE 6
respuesta = v1 * v1 * v1
'xn
CASE 7
IF VISOR.Text <> "" THEN

' respuesta =
ENDIF
'1/x
CASE 8
'octal
CASE 9
respuesta = v1
END SELECT
RETURN respuesta

END

PUBLIC SUB VISOR_KeyPress()
END

'X3
PUBLIC SUB Button20_Click()
ban = 6
IF VISOR.Text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF
END

'Xn
PUBLIC SUB Button21_Click()
ban = 7
IF VISOR.Text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF


END
'hexadecimal
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
'Message("pulse aceptar para continuar..", "Aceptar")
END

PUBLIC SUB Button24_Click()
DIM ra AS Float
ra = Rad(VISOR.Text)
VISOR.Text = Cos(ra)
END

PUBLIC SUB Button25_Click()
DIM ra AS Float
ra = Rad(VISOR.Text)
VISOR.Text = Tan(ra)

END

PUBLIC SUB Button23_Click()
DIM ra AS Float
ra = Rad(VISOR.Text)
VISOR.Text = Sin(ra)
END

'1/x
PUBLIC SUB Button22_Click()
ban = 8
IF VISOR.Text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF

END

'Optal
PUBLIC SUB Button32_Click()
ban = 9
IF VISOR.Text <> 0 THEN
aux1 = VISOR.Text
ELSE
aux1 = 0
ENDIF
END

OPERACION FACTORIAL

ESTE EJERCICIO ES PARA REALIZAR UNA OPERACION FACTORIAL

Nota: Este ejercicio esta realizado con un ciclo for next para optimizar de una manera efectiva este proceso.........

PUBLIC SUB Main()
DIM nombre, res AS String
DIM f, l, i AS Integer
f = 1
FOR i = 2 TO 5
f = f * i
NEXT
PRINT "el factorial de 5 es ", f

PRINT "Ingrese nombre "
INPUT nombre
l = Len(nombre)
PRINT "\n"
PRINT "El resultado es:"
FOR i = 1 TO l
res = Mid(nombre, i, 1)
PRINT res
NEXT

nota: esperando que con estas instrucciones le sirva de guia para practica y desarrollo de un gran proyecto a medida que vas practicando y conociendo mas del programa y desarrollando la logica....

CODIGO DE LA "OPERACION SUMA" LLAMANDO A LA CLASE MEDIANTE FUNCIONES

EJERCICIO DE LAS OPERACIONES SUMA, RESTA, MULTIPLICACION REALIZADO CON FUNCION EN LA CLASE

Nota: Al dentrar en gambas con doble clic, luego clic en:
Nuevo Proyecto, luego Aplicacion de consola escojer el directorio (carpeta) luego siguiente y Programar o Ingresar el codigo. (Programacion).


CODIGO DE INICIO DANDO DOBLE CLIC EN EL MODULO MMain

PUBLIC SUB Main()

DIM operac AS operaciones
DIM num1, num2 AS Integer

operac = NEW operaciones

PRINT "Ingrese primer numero..."
INPUT num1
PRINT "Ingrese segundo numero..."
INPUT num2

operac.asignumero(num1, num2)
operac.sumarestmult(num1, num2)

END

LLAMADA DE LA CLASE DANDO CLIC DERECHO NUEVO Y CLIC EN CLASE

PRIVATE num1 AS Integer
PRIVATE num2 AS Integer

PUBLIC SUB asignumero(nume1 AS Integer, nume2 AS Integer)
num1 = nume1
num2 = nume2

END

PUBLIC FUNCTION sumarestmult(num1 AS Integer, num2 AS Integer)
DIM s1, r1, m1 AS Integer

s1 = num1 + num2
r1 = num1 - num2
m1 = num1 * num2

PRINT "la suma es :", s1
PRINT "la resta es :", r1
PRINT "la Multiplicacion es :", m1

END