Академический Документы
Профессиональный Документы
Культура Документы
End Sub
Private Sub Label4_Click()
Label1.caption = "Teclado"
End Sub
Ejercicio N 2: Crucigrama.
Comenzamos un
nuevo proyecto.
Con este ejercicio
queremos sugerir
una ejemplo de
crucigrama que cada
uno podr adaptar a
los contenidos
requeridos. Tambin
a partir de aqu
podramos elaborar
un Ahorcado.
El crucigrama est armado con cuadros de texto o sea controles
Text, encerrados dentro de un control frame, este control tiene la
nica finalidad de agrupar y contener otros controles, ordenando la
interactividad de una manera visual. Otros dos controles Frame
agrupan las opciones vertical y horizontal. Conteniendo controles
CheckBox que al ser seleccionados hacen la correccin de las letras
ingresadas en las cajas de texto. El ingreso de las mismas se hace
en tiempo de ejecucin a travs del teclado.
A la derecha vemos unos controles Picture vacos que se cargaran
con imgenes que muestren por ejemplo una cara sonriente si la
palabra es correcta o seria si no lo es, o cualquier otro tipo de
imagen .Podemos llamar a esta imagen con la funcin LoadPicture
desde cualquier parte de nuestro disco rgido. Y un botn con el
icono de Hijitus indica la Salida y cierre del programa.
Ac tendremos que crear por cdigo una estructura condicional que
controle si la entrada de datos es correcta o no.
El cdigo es el siguiente:
Private Sub Command1_Click()
End
End Sub
Private Sub Check1_Click()
If Text1.Text = "L" And Text2.Text = "O" And Text3.Text= "R" And
Text4.Text ="O" then ' este cdigo debe ir todo en un mismo regln y
'chequea si se escribi una de las palabras correctas. Ciudado con
los 'nombres de los Controles porque seguramente Ustedes no
tendrn la 'misma numeracin que yo. (Otra aclaracin cuando
usamos el carcter ' 'indicamos que todo lo que sigue es un
comentario, por lo tanto la 'computadora no lo ejecuta lo saltea, no
es cdigo).
Image1. Picture = LoadPicture(c:\vb\Icons\Misc\Face03.ico) 'carita
linda
Else 'Sino
Image1. Picture = LoadPicture(c:\vb\Icons\Misc\Face01.ico) 'carita fea
End Sub
Private Sub Check2_Click()
If Text2.Text = "O" And Text5.Text ="R" And Text9.Text ="O" then
Image2.Picture = LoadPicture(c:\vb\Icons\Misc\Face03.ico) 'carita
linda
Else 'Sino
Image2. Picture = LoadPicture(c:\vb\Icons\Misc\Face01.ico) 'carita fea
End Sub
Private Sub Check3_Click()
If Text7.Text = "R" And Text8.Text ="A" And Text9.Text ="T" And
Text4.Text ="O" And Text10.Text ="N" then
Image3. Picture = LoadPicture(c:\vb\Icons\Misc\Face03.ico) 'carita
linda Else 'Sino
Image3. Picture = LoadPicture(c:\vb\Icons\Misc\Face01.ico) 'carita fea
End Sub
Ejercicio N 4: Sumas.
Command2.Enabled = False
Image1.Picture = Nothing 'vaca el contenido de la imagen
End Sub
Private Sub Command2_Click()
Command2.Enabled = False
resultado = Val(Text1.Text)
If resultado = Int(num1) + Int(num2) Then
Image1.Picture = Picture1.Picture
Call pausa ' llama al procedimiento que creamos como Pausa
Call Command1_Click 'este procedimiento llama a otra suma
Else
Image1.Picture = Picture2.Picture
End If
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
Randomize
num1 = Int(Rnd * 10)'al cargarse el programa ya aparece una cuenta
num2 = Int(Rnd * 10)
Text1.Text = ""
Label1.Caption = num1'se vuelcan las variables en las Labels
Label2.Caption = num2
Ejercicio N 5: Torero.
La sucesin de imgenes la
realiza un control Timer
asociado a un contador , cada
imagen se relaciona con un
texto que desplegamos en una
Label colocada debajo de la
imagen central. Al llegar el
contador a 12 se detiene la
sucesin y se muestra una Label
con los nombres de los
creadores de la aplicacin.
La Label = Reiniciar nos posibilita volver a comenzar sin salir de la
aplicacin, para esto inicializa la variable A = 0 y pone el Timer
nuevamente en funcionamiento.
El cdigo de los principales procedimientos es el siguiente:
Option explicit
Dim A as Integer
Private Sub Label3_Click() ' esta es la label de reiniciar
Timer1.enabled = True
A=0
Label2.caption = "Lo primero es la coleta..."
Label4.visible = False ' oculta a los Autores
End Sub
Private Sub Timer1_Timer()
A=A+1
If A = 3 then
Image13.Picture= Image1.Picture
Label2.caption = "Y los tirantes despus..."
ElseIf A = 4 then
Image13.Picture = Image5.Picture
Label2.caption = "enseguida la corbata..."
Elseif A = 5 Then ' Y as las distintas opciones de Imgenes y de
Texto.
Label4.Visible = True ' muestra los Autores
Timer1.enabled = False ' desactiva el Timer
End If
End Sub
Controlen el orden de las Imgenes de acuerdo a su propia
aplicacin, y los textos siguientes son:
"Y una faja de chip..."
"El chaleco hay que ensancharlo ..."
Al pasar el puntero del mouse sobre el planeta este cambia por una
manito lo que nos indica que es posible una interaccin. Y al clickear
sobre el mismo despliega en la Label inferior el nombre del planeta.
Vamos a centrarnos en las novedades que aporta este ejercicio en
relacin al N1. Primero : podemos cambiar el puntero del mouse:
Para esto en la propiedad MousePointer y MouseIcon de cada Label
transparente haremos cierta modificaciones.
MousePointer = 99 (Custome) ' O sea la opcin personalizada.
MouseIcon = Seleccionamos de la carpeta Icons o de otra en
especial el Icono que queremos mostrar.
Segundo : Vemos en la Imagen Inferior que muestra la Aplicacin en
ejecucin, dos botones : uno de Imprimir y otro de Salir, que en
realidad no son Botones porque su forma es ovalada. Estos son
Controles Shape de forma ovalada . Como el Control Shape es
puramente decorativo y no responde a ningn Evento , entonces
aqu tambin con un pequeo truco , le colocamos una Label
transparente sobre la Shape con la propiedad Caption = Imprimir o
Salir y ahora s la Label responde al Evento Click.
Tercero: En la Shape Imprimir , al clickear sobre ella imprimimos el
Ejercicio N 7: Cubos.
Este ejercicio y los tres
siguientes usan en sus
procedimientos el Drageo o Drag
and Drop , que significa arrastrar
y soltar y nos va a permitir
mover un objeto en tiempo de
ejecucin de un lugar a otro del
formulario. Este tipo de
ejercicios es muy til para los
docentes que trabajan con los
ms pequeos.
Usamos tres controles Picture cargando en cada uno de ellos un
icono que les guste. Y en la propiedad Dragmode de cada picture
elegimos la opcin Automatic , la numero 1. Esto permitir mover los
controles. Pero para que realmente se desplacen debemos agregar
al procedimiento Form_DragDrop el siguiente cdigo:
Private Sub DragDrop ( Source as control, X as Single, Y as Single)
Source.Move x, y
End Sub
Dentro de los argumentos entre parntesis vemos Source que quiere
decir origen, o sea el control de origen y esto es muy importante
porque quiere decir que no hace falta que especifiquemos que
picture estamos moviendo o arrastrando y soltando , el
procedimiento lo registra de por s, y lo que debemos actualizarle
son las nuevas coordenadas que leer el procedimiento a travs de
x, y. Aqu usamos un mtodo ya conocido el Move. Al correr el
programa podemos clickear sobre una de las figuras y manteniendo
el botn izquierdo del mouse apretado arrastrarla a la nueva
posicin que deseamos y luego soltarla.
Ejercicio N 8: Da Feliz.
Los controles son cuatro Image , el botn que borra el total a pagar.
Una caja de texto que muestra el total y las dems son Labels
indicativas.
Cuando arrastramos la imagen vamos a observar que no drageamos
un rectngulo o ventana vaca sino iconos que coinciden con la
imagen elegida, para eso a cada imagen le cargamos su icono
correspondiente en la propiedad DragIcon. No olvidarse poner la
propiedad DragMode en 1. El cdigo es el siguiente:
Dim total as integer ' Declaramos en la parte General la variable.
Private Sub Command1_Click()
Text1.text = "" ' vacimos la caja de texto.
Total = 0 ' reiniciamos la variable a 0.
End Sub
Private Sub Image4_dragDrop (...) ' En imagen de la calculadora.
If Source = Image1 then ' Aqu testeamos la imagen de origen.
Total = total + 260
Elseif Source = Image2 then
Total = total + 300
Elseif Source = Image3 then
Total = total + 1400
End if
Text1.text = total
End Sub
End Sub
Printer.Print
'Un rengln en blanco o salto de carro
Printer.Print
Printer.Print
Printer.Print Tab(15); Label1.Caption; Tab(30);
Text1.Text
'Aqu damos la orden de impresin del caption de
la label1 a 15 espacios 'del margen izquerdo y
luego a 30 espacios del margen izquierdo el
'contenido del texto.
Printer.Print
Printer.Print
Printer.Print Tab(15); Label2.Caption; Tab(30);
Text2.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label3.Caption; Tab(30);
Text3.Text
Printer.Print
Printer.Print
Printer.Print
Printer.Print Tab(15); Label4.Caption; Tab(30);
Text4.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label5.Caption; Tab(30);
Text5.Text
Printer.Print
Printer.Print
End Select
End Sub
En el procedimiento click de laToolbar mediante un
Select Case asociamos cada botn a una imagen
distinta de la ImageList y al cliquear
desencadenamos la funcin MsgBox que nos
identifica el botn al que nos referimos. Aqu juega
un papel importante la propiedad Key que
identifica a la imagen, como nica y no puede
repetirse.
La sentencia Set determina la asociacin entre los
controles, fijndola.
Timer1.Enabled = False
Command1.Caption = "Animacin"
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
PictureClip1.Cols = 4
PictureClip1.Rows = 1
PictureClip2.Cols = 4
PictureClip2.Rows = 1
'Es mejor determinar la composicin de la grilla por
cdigo ya que a veces 'al salir del programa el
control Pictureclip no retiene los valores de la
'ventana de propiedades y vuele a su 1 a 1 por
defecto.
End Sub
Private Sub Timer1_Timer()
Picture1.Refresh
Dim x As Single, y As Single
Static imagenactual As Integer
Static xactual As Integer
If imagenactual > 3 Then imagenactual = 0
If imagenactual < 0 Then imagenactual = 0
If xactual > 500 Then xactual = 0
If xactual < 0 Then xactual = 0
WebBrowser1.Navigate Text1.Text
If WebBrowser1.Visible = False Then
WebBrowser1.Visible = True
End If
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then 'equivale a la tecla Enter
Command1_Click
End If
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As
ComctlLib.Button)
Select Case Button.Key
Case "back" 'se identifica por la Key
On Error Resume Next
WebBrowser1.GoBack 'Retrocede
Case "forward"
On Error Resume Next
WebBrowser1.GoForward 'Adelanta
Case "home"
Text1.Text = "http://www.reocities.com/SiliconValley/Garage/6472"
Command1_Click
Case "refresh"
WebBrowser1.Refresh 'actualiza o refrezca
Case "stop"
WebBrowser1.Stop 'detiene la bsqueda
End Select
End Sub
Private Sub WebBrowser1_DownloadBegin()
StatusBar1.Panels(1).Text = "Cargando Pgina..."
End Sub
Private Sub WebBrowser1_DownloadComplete()
StatusBar1.Panels(1).Text = "Listo"
End Sub
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X
As Single, Y As Single)
If draw Then Line -(X, Y) ' si la variable draw esta a verdadera 'dibuja
cada uno de los puntos.
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
draw = False 'la variable draw a falsa detiene el dibujo
End Sub
El formulario de evaluacin
se asemeja al siguiente:
Y el cdigo es:
Private Sub Picture1_Click() 'imagen de Jpiter
planeta = InputBox("Qu planeta es este?", "Planetas")
If UCase(planeta) = "JPITER" Then
contar = contar + 1
Label2.Caption = contar
End If
satelite = InputBox("Cuntos satlites tiene?", "Planetas")
If satelite = "16" Then
contar = contar + 1
Label2.Caption = contar
Picture1.Enabled = False
End If
End Sub
Tambin incluimos una variable contar para que nos sume puntos
con las respuestas correctas, y las variables planeta y satlite que
guardan las respuestas del InputBox. Esta variables deben ser
declaradas en la parte general del formulario.
Para cerrar tenemos el formulario crditos donde se indica el
nombre del programador y el botn Salir que cierra la aplicacin. La
navegacin entre un formulario y otro se realiza mediante los
mtodos Show: Mostrar y Hide: Ocultar. Primero se muestra el
formulario vinculado y luego se oculta el que est activo. Ejemplo:
Private Sub Label1_Click()
Form3.Show
Form5.Hide
End Sub
Ustedes pueden vincular distintos formularios con distintos
ejercicios, imgenes, animaciones o videos o simplemente
informacin escrita.
PC?"
Image1.Visible = True
ElseIf UCase(nombreusuario) = "MIRTA" And LCase(contrasea) =
"duende" Then
MsgBox "BIENVENIDA MIRTA AL SISTEMA! A trabajar no te
duermas!"
Image1.Visible = True
Else
MsgBox "ACCESO DENEGADO"
End If
Adems de darnos el acceso con un saludo despliega una imagen en
un control Image, en caso de no ser la contrasea o el nombre del
usuario el indicado nos niega el acceso. Pueden bajar el ejercicio
de Aqu.
Image9.Visible = False
Label1.Caption = "Correcto!"
Label2.Caption = "Craneo"
Beep
Else
Label1.Caption = "Incorrecto!"
End If
Call fin
End Sub
El procedimiento fin es el que testea si esta es la ltima pieza
colocada y su cdigo es:
Private Sub fin()
If Image9.Visible = False And Image10.Visible = False And
Image11.Visible = False And Image12.Visible = False And
Image13.Visible = False And Image14.Visible = False And
Image15.Visible = False And Image16.Visible = False Then
Beep
Label2.Caption = ""
Label1.Caption = "Ganaste!"
End If
End Sub
El ejercicio completo puede bajarse de Aqu.
En este ejercicio
vamos a usar el Editor
de men de Visual
Basic, que nos permite
crear un men con las
caractersticas de
windows. Para poder
activarlo debemos
estar en la ventana de
formulario u objeto, no
en la de cdigo.
Mediante botones de
opcin vamos a hacer
visibles o invisibles los
mens que hemos
diseado, en este caso
el tema ser platos de
comida y los mens
sern sobre: Platos
fros, calientes y
postres. El programa
ejecutado se v as:
Posicionados en la
ventana formulario
activamos el Editor
mediante el cono
y cuando se abre la
ventana vamos
configurado los
distintos item del men
como se ve en la
siguiente imagen:
Aqu hay dos propiedades muy importantes, el caption del men que
ser el ttulo que aparezca en el men y el name del men, el caption
puede estar vaco pero el name no, Y vamos anidando los submens
que queremos incorporar, como lo muestra la imagen, para
desplegar un submen hacemos click en next y en la flecha hacia la
derecha para hacer una sangra que indica los subtemas del men.
Cada integrante del men responde a un solo evento que es el Click.
Para probarlo podemos agregar el siguiente cdigo en el evento
click de cada men:
MnuFiambres_Click()
MsgBox "haz hecho click en la opcin bandeja de Fiambres"
End Sub.
Esto no est includo en el ejercicio, pero puede agregarle cualqier
Lo original de este
ejercicio es que el
archivo al ejecutarse
no lo hace en otra
ventana, sino en un
control Picture.
El cdigo es el siguiente:
Private Sub video()
MMControl1.DeviceType = "AVIVideo"
MMControl1.filename = App.Path & "\ugachaka.Avi"
MMControl1.Command = "open"
MMControl1.hWndDisplay = Picture1.hWnd
MMControl1.Command = "play"
End Sub
Private Sub Command1_Click()
Call video
End Sub
Primero creamos un procedimiento llamado video y all volcamos las
indicaciones de la ejecucin, pero Atencin! Usamos la propiedad
Handle Window para manipular en que objeto se ejecuta el avi.
Windows identifica as que queremos que se despliegue en la
picture, a traves de la propiedad hWnd del control multimedia y de
hWnd del control Picture.
El cdigo completo sin el AVI puede bajarse de Aqu.
Este ejercicio lo
podemos hacer y
llevar, su arranque al
trabajo y preguntarle a
nuestros colegas, o
compaeros si Est
conforme con el
sueldo que gana.
Como damos por
supuesto que la
mayora va a
contestarnos que No,
hicimos un pequeo
chiste , ya que al
querer hacer Click en
el Botn de No, este se
nos escapar.
El cdigo es el siguiente:
Private Sub Command1_Click()
End
End Sub
Private Sub Command2_Click()
MsgBox "Sufre el mismo mal que millones de Argentinos!!"
End Sub
Private Sub Command2_MouseMove(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Command2.Move CInt(Rnd * (Width - Command2.Width)), CInt(Rnd *
(Height - Command2.Height))
End Sub
Con el Botn Si: salimos del programa y al querer hacer click en el
botn: No, se mueve aleatoriamente a una nueva posicin entre las
medidas de ancho y alto del formulario.
El cdigo del ejercicio pueden bajarlo de Aqu.
En este ejercicio,
simplemente entramos
en tiempo de ejecucin
una temperatura para
cada da de la semana
y luego haciendo click
en los botones: Alta,
Media y Baja , devuelve
los valores en otras
cajas de texto. El
cdigo es el siguiente:
Option Explicit
Dim alta As Single
Dim dia As Integer
Dim baja As Single
Dim media As Single
Private Sub Command1_Click() ' mostrar el valor ms alto de los
textbox() en el text Alta
alta = Text1(0).Text
For dia = 1 To 6
If Text1(dia).Text > alta Then
alta = Text1(dia).Text
End If
Next dia
Text2.Text = alta
End Sub
Private Sub Command2_Click() 'calcular la ms baja y lo muestra en
el Text1(0).Text
For dia = 1 To 6
If Text1(dia).Text < baja Then
baja = Text1(dia).Text
End If
Next dia
Text3.Text = baja
End Sub
Private Sub
Command3_Click() 'calcula la media de los contenidos de text1()
Dim total As Single
Dim promedio As Single
total = 0
For dia = 0 To 6
total = total + Text1(dia)
Next dia
promedio = total / 7
Text4.Text = Format(promedio, "##.##") 'formato con dos decimales
End Sub
Private Sub Command4_Click()
For dia = 0 To 6
Text1(dia).Text = ""
Next dia
Text1(0).SetFocus
End Sub
Private Sub Command5_Click()
End
End Sub
Usando estructuras de repeticin For Next, calculamos los valores
Option Explicit
Private Sub Command1_Click()'el boton Salir cierra el programa
End
End Sub
Private Sub Command2_Click() 'este boton corrige si estan bien
'colocadas las imagenes. Debe escribirse todo el cdigo 'seguido o
cortarlo usando el under _
If Picture1.Picture = Image1(2).Picture And Picture2.Picture =
Image1(1).Picture And Picture3.Picture = Image1(5).Picture And
Picture4.Picture = Image1(0).Picture And Picture5.Picture = Image1(4)
And Picture6.Picture = Image1(3).Picture Then
Picture1.Visible = False
Picture2.Visible = False
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible =
False Image2.Visible = True 'carga otra imagen oculta que 'muestra
un gato completo
Else 'sino es correcto vaca las imagenes para reiniciar el 'armado
del rompecabezas.
Picture1.Picture = Nothing
Picture2.Picture = Nothing
Picture3.Picture = Nothing
Picture4.Picture = Nothing
Picture5.Picture = Nothing
Picture6.Picture = Nothing
End If
End Sub
Private Sub Form_Activate()' al cargarse el form y pasar a estar
'activo carga las celdas o partes en que dividimos la imagen con 'el
PictureClip.
Image1(0).Picture = PictureClip1.GraphicCell(3) Image1(1).Picture =
PictureClip1.GraphicCell(1) Image1(2).Picture =
PictureClip1.GraphicCell(0) Image1(3).Picture =
PictureClip1.GraphicCell(5) Image1(4).Picture =
PictureClip1.GraphicCell(4) Image1(5).Picture =
PictureClip1.GraphicCell(2)
End Sub
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As
Single)
Picture1.Picture = Source
End Sub
Private Sub Picture2_DragDrop(Source As Control, X As Single, Y As
Single)
'carga las imagenes de origen al soltarlas
Picture2.Picture = Source
End Sub Private Sub Picture3_DragDrop(Source As Control, X As
Single, Y As Single)
Picture3.Picture = Source
End Sub
Private Sub
Picture4_DragDrop(Source As Control, X As Single, Y As Single)
Picture4.Picture = Source
End Sub
De acuerdo a su valor
este determinar el
color del fondo del
formulario, y del tipo
de un terce control
Text. La aplicacin se
as:
Text3.BackColor = QBColor(HScroll1.Value)
End Sub
Private Sub
HScroll1_Scroll()
Text1.Text = HScroll1.Value
Text3.BackColor = QBColor(HScroll1.Value)
End Sub
Private Sub
HScroll2_Change()
Text2.Text = HScroll2.Value
Text3.ForeColor = QBColor(HScroll2.Value)
End Sub
Private Sub
HScroll2_Scroll()
Text2.Text = HScroll2.Value
Text3.ForeColor = QBColor(HScroll2.Value)
End Sub
El cdigo completo puede bajarse de Aqu.
Dim controlar
Dim comenzar
comenzar = Timer
Do Until controlar >= comenzar + 0.2
controlar = Timer
DoEvents
Loop
End Sub
El cdigo completo puede bajarse de Aqu.
En este ejercicio
vamos a usar un
ActiveX que permite
hacer efctos de
transicin entre varias
imagenes, es un
shareware, bajado de
Internet, muy fcil de
usar. El form se ve as:
El cdigo es el siguiente:
Option Explicit
Public pc, i As Integer
Private Sub Command1_Click()
Do
DoEvents
TransFX1.Effect = i
TransFX1.Start
Set TransFX1.PicBuffer = LoadPicture(App.Path & "\" &_ CStr(pc) &
".jpg")
pc = pc + 1: If pc > 3 Then pc = 1 i = i + 1: If i = 13 Then i = 1 Loop
End Sub
Private Sub
Command2_Click()
End
End Sub
Private Sub Form_Load()
pc = 1
i=1
Set TransFX1.PicTarget = LoadPicture(App.Path & "\" &_ CStr(pc) &
".jpg")
Set TransFX1.PicBuffer = LoadPicture(App.Path & "\" &_ CStr(pc + 1)
& ".jpg")
End Sub
Las propiedades principales son: PicTarget que es la primera imagen
que carga y PicBuffer las siguientes, como minimo debemos tener 2
imagenes , pero podemos cargar varias ms. Y el mtodo Start que
lo inicia, podramos usar un timer pero en este caso es un bucle el
que repite la operacin pasando entre los 15 efectos posibles que
permite el control.
Por cualquier duda incluyo el archivo de Ayuda del creador del
activeX. Los archivos con el control pueden bajarse de Aqu.
Este ejercicio es un
juego muy simple que
al hacer click en los
insectos, si estan
prximos a la rana,
sta simula comerlos y
suma un puntaje.
controlar = Timer
DoEvents
Loop
End Sub
Private Sub Form_Load()
Randomize b = 0
End Sub
Private Sub Image6_Click(Index As Integer) Image6(Index).Visible =
False
b = b + 10
If Image6(Index).Left >= 2600 Then
Image7.Visible = True
ret = sndPlaySound(App.Path & "\Frogs.wav", SND_ASYNC Or
SND_NODEFAULT)
ElseIf Image6(Index).Left <= 2600 Then
Image8.Visible = True
ret = sndPlaySound(App.Path & "\Frogs.wav", SND_ASYNC Or
SND_NODEFAULT)
End If
Call pausa
Image7.Visible = False
Image8.Visible = False
Label1.Caption = "Puntaje =" & b
Call ganar
Call perder
End Sub
For a = 0 To 9
Image6(a).Move CInt(Rnd * (Width - Image6(a).Width)), CInt(Rnd *
(Height - 1600))
Next a
End Sub
Private Sub ganar()
If b = 100 Then
Label1.Caption = "GANASTE!!"
ret = sndPlaySound(App.Path & "\Fanfare.wav", SND_ASYNC Or
SND_NODEFAULT)
End If
End Sub
Private Sub perder()
If tiempo = 60 Then
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Label1.Caption = "Perdiste!!"
ret = sndPlaySound(App.Path & "\desapa.wav", SND_ASYNC Or
SND_NODEFAULT)
End If
End Sub
Private Sub
Timer3_Timer() tiempo = tiempo + 1
Call perder
End Sub
Randomize
For I = 1 To 20 temparray(I) = I
Next I
Top = 20
For I = 1 To 20
idxtemp = Int(Top * Rnd + 1)
numero(I) = temparray(idxtemp)
For J = idxtemp To Top - 1
temparray(J) = temparray(J + 1)
Next J
Top = Top - 1
'Print numero(I)
Next I
End Sub
Private Sub Command1_Click()
If I > 1 Then
Label1.Caption = numero(I - 1)
Call mostrar
I=I-1
Else
Call azar
End If
End Sub
Private Sub
Command3_Click()
End
End Sub
Private Sub Command4_Click()
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub
Form_Activate()
Text1.SetFocus
End Sub
Private Sub
Form_Load()
Randomize
Call azar
Call Command1_Click
End Sub
Private Sub mostrar()
Select Case Label1
Case 1
Command2.Picture = Image1(0).Picture
Case 2
Command2.Picture = Image1(1).Picture
Case 3
Command2.Picture = Image1(2).Picture
Case 4
Command2.Picture = Image1(3).Picture
Case 5
Command2.Picture = Image1(4).Picture
Case 6
Command2.Picture = Image1(5).Picture
Case 7
Command2.Picture = Image1(6).Picture
Case 8
Command2.Picture = Image1(7).Picture
Case 9
Command2.Picture = Image1(8).Picture
Case 10
Command2.Picture = Image1(9).Picture
Case 11
Command2.Picture = Image1(10).Picture
Case 12
Command2.Picture = Image1(11).Picture
Case 13
Command2.Picture = Image1(12).Picture
Case 14
Command2.Picture = Image1(13).Picture
Case 15
Command2.Picture = Image1(14).Picture
Case 16
Command2.Picture = Image1(15).Picture
Case 17
Command2.Picture = Image1(16).Picture
Case 18
Command2.Picture = Image1(17).Picture
Case 19
Command2.Picture = Image1(18).Picture
Case 20
Command2.Picture = Image1(19).Picture
End Select
End Sub
Private Sub
Text1_Change()
Call corregir
End Sub
Private Sub corregir()
Static puntos As Integer
Select Case Label1
Case 1
If UCase(Text1.Text) = "CARAMBOLA" Then
puntos = puntos + 1
Case 2
End Sub
Private Sub Timer1_Timer()
a=a+1
If a >= 7 Then
a=0
Picture1.Picture = Image1(a).Picture
End Sub
La aplicacin completa puede bajarse de Aqu.
For Y = 0 To
Destination.ScaleHeight _ Step Source.ScaleHeight
For X = 0 To
Destination.ScaleWidth Step _ Source.ScaleWidth
Destination.PaintPicture _ Source.Picture, X, Y
Next 'X
Next 'Y
End Sub
Usamos el Mtodo PaintPicture ya conocido en nuestras
animaciones, para copiar la imagen en el fondo del formulario. En un
bucle anidado For Next que repite el ancho y el alto de la imagen.
Luego lo convocamos desde el Formulario en el Click de un Array de
imagenes, que muestran distintas opciones de dibujo:
Private Sub picSource_Click(Index As Integer)
'Toma la imagen del array de controles y la copia en el formulario
'como un mosaico repetido.
TileBitmap picSource(Index), Me
End Sub
Convoca al procedimiento pblico del Mdulo y lo vuelca en el
Formulario activo o sea Me.
El ejercicio completo puede bajarse de
Aqu.
End Sub
El mtodo Refresh refresca la imagen de la Picture donde se ejecuta
el Mtodo Draw. Los argumentos de este mtodo son el controlador
de contexto de dispositivo (HDC) del objeto que lo recibe o sea la
Picture1.hDC, su ubicacin en las coordenadas x, y, y el estilo
grfico transparente correspondiente al valor del color de la
propiedad MaskColor del ImageList.
El ejercicio completo puede bajarse de
Aqu.
Aqu.
Call frasedoctor
List1.AddItem "tu"
List1.AddItem "te"
List1.AddItem "pienso"
List1.AddItem "bien"
List1.AddItem "regular"
List1.AddItem "que"
List1.AddItem "quiero"
List1.AddItem "deprimido"
List1.AddItem "sin"
List1.AddItem "dificil"
List1.AddItem "esperar"
List1.AddItem "necesito"
List1.AddItem "por que?"
List1.AddItem "se"
List1.AddItem "adios"
List1.AddItem "odio"
List1.AddItem "amor"
List1.AddItem "asesino"
List1.AddItem "matar"
List1.AddItem "grosero"
List1.AddItem "no puedo"
List1.AddItem "fracaso"
List1.AddItem "nunca"
List1.AddItem "infeliz"
'Text1.Text = List1.List(3)
End Sub Private
Sub frasedoctor()
frase = Int(Rnd * 8)
Select Case frase
Case 0
Label1.Caption = "Cmo est Ud.?"
Case 1
Label1.Caption = "Cul es su estado de nimo?"
Case 2
Label1.Caption = "Tuvo Ud. una infancia feliz?"
Case 3
Label1.Caption = "Es feliz con el medio que lo rodea?"
Case 4
Label1.Caption = "Tiene problemas para relacionarse?"
Case 5
Label1.Caption = "Odia Ud. a su padre?"
Case 6
Label1.Caption = "Cree que no lo comprenden?"
Case 7
Label1.Caption = "Yo no estoy seguro de entenderlo"
End Select
End Sub
Case "te"
Label1.Caption = "Dejemos de hablar de mi."
Case "pienso"
Label1.Caption = "Por qu piensa eso?"
Case "bien"
Label1.Caption = " Me alegra, cunteme sobre Ud."
Case "regular"
Label1.Caption = "Entiendo, Cuenteme sobre Ud."
Case "que"
Label1.Caption = "Por qu pregunta Ud.?"
Case "quiero"
Label1.Caption = "Por qu quiere usted eso?"
Case "deprimido"
Label1.Caption = "Qu lo deprime?"
Case "sin"
Label1.Caption = "Entiendo. Cree que lo puede remediar?"
Case "por que"
Label1.Caption = "Recuerde, la terapia es buena para Ud."
Case "dificil"
Label1.Caption = "No se preocupe, ya cambiarn las cosas."
Case "esperar"
Label1.Caption = "Tenga algo de paciencia."
Case "necesito"
Label1.Caption = "Todos necesitamos cosas."
Case "se"
Label1.Caption = "Como sabe Ud. eso?"
Case "odio"
Label1.Caption = "El odio nunca conduce a nada bueno"
Case "amor"
Label1.Caption = "Es importante amar"
Case "asesino"
Label1.Caption = "No me gusta la gente que mata"
Case "matar"
Label1.Caption = "No esta bien matar"
Case "grosero"
Label1.Caption = "No esta bien que me hable as!"
Case "no puedo"
Label1.Caption = "No sea negativo, sea positivo"
Case "fracaso"
Label1.Caption = " Debe luchar por el exito"
Case "nunca"
Label1.Caption = "No sea negativo, sea positivo"
Case "infeliz"
Label1.Caption = "Por que es infeliz?"
Case "adios"
Label1.Caption = "Le enviar la factura. Gracias."
RichTextBox1.Locked = True
Beep
Call pausa
End Case
Else
Call frasedoctor
End Select
End Sub
El cdigo completo puede bajarse de AQU.
E este es un ejercicio
muy simple que dibuja
puntos en un
formulario. Vamos a
empezar a ver cierta
funciones grficas de
visual basic. Lo
importante para que se
salgan por impresora
es que la propiedad
AutoRedraw del
formulario este a True.
Sino no se ven los
puntos en la
impresin.
El cdigo del ejercicio es:
Option Explicit
Private Sub Command1_Click()
Dim x As Integer
Dim y As Integer
Dim color As Integer
Dim i As Integer
For i = 1 To 20
x = Int(ScaleWidth * Rnd)
y = Int(ScaleHeight * Rnd)
color = Int(16 * Rnd)
PSet (x, y), QBColor(color)
Next
End Sub
Private Sub
Command2_Click()
Cls
End Sub
Private Sub Command3_Click()
Form1.PrintForm
End Sub
Private Sub Form_Load()
Randomize
End Sub
Como vemos usamos la funcin randomize para ubicar los puntos
en forma aleatoria en el formulario y un bucle For/Next que dibuja 20
puntos por cada click que hacemos en el botn: Puntos, el otro
botn borra con Cls lo dibujo o sea limpia el form. El mtodo Pset
(Point Set) dibuja los puntos combinada con QBColor que le asigna
un color. El formato de los puntos es Dot.
El ejercicio completo pueden bajarlo de AQU.
Option Explicit
Dim x, y, r As Integer
Dim x1 As Integer, y1 As Integer
Dim x2 As Integer, y2 As Integer
Dim color As Integer
Dim ccolor As Integer
Private Sub Command1_Click()'Botn Rectas
'puntos extremos y color aleatorio
x1 = Fix(Me.ScaleWidth * Rnd)
y1 = Fix(Me.ScaleHeight * Rnd)
x2 = Fix(Me.ScaleWidth * Rnd)
y2 = Fix(Me.ScaleHeight * Rnd)
color = Fix(16 * Rnd) Randomize
'trazar una recta
Line (x1, y1)-(x2, y2), QBColor(color) 'los dos primeros valores
'establecen un punto extremo y los otros dos el otro punto extemo,
'entre ambos se dibuja la recta.
End Sub
Private Sub Command2_Click() 'Botn Imprimir por Impresora.
Me.PrintForm
End Sub
Private Sub Command3_Click() 'Botn Rectngulo
x1 = Fix(Me.ScaleWidth * Rnd)
y1 = Fix(Me.ScaleHeight * Rnd)
x2 = Fix(Me.ScaleWidth * Rnd)
y2 = Fix(Me.ScaleHeight * Rnd)
color = Fix(16 * Rnd)'elige al azar un color
Randomize FillStyle = 1
'dibuja un cuadro(B)
Line (x1, y1)-(x2, y2), QBColor(color), B
End Sub
Private Sub Command4_Click() 'Botn Rectngulo relleno
x1 = Fix(Me.ScaleWidth * Rnd)
y1 = Fix(Me.ScaleHeight * Rnd)
x2 = Fix(Me.ScaleWidth * Rnd)
y2 = Fix(Me.ScaleHeight * Rnd)
color = Fix(16 * Rnd)Randomize
'dibuja un cuadro(B)
Line (x1, y1)-(x2, y2), QBColor(color), BF
End Sub
Private Sub Command5_Click() 'Borra o Limpia Formulario
Cls
End Sub
Private Sub Command6_Click() 'Botn Crculo relleno
'coordenadas del Centro, Radio y Color, aleatorias
x = Fix(Me.ScaleWidth * Rnd)
y = Fix(Me.ScaleHeight * Rnd)
r = Fix(1000 * Rnd)
color = Fix(16 * Rnd)
Randomize
FillStyle = 1'rellena el crculo
'dibuja una circunferencia
Circle (x, y), r, QBColor(color)
End Sub
Private Sub Command7_Click() 'Botn Crculo
x = Fix(Me.ScaleWidth * Rnd)
y = Fix(Me.ScaleHeight * Rnd)
r = Fix(1000 * Rnd)
color = Fix(16 * Rnd)
ccolor = Fix(16 * Rnd)
Randomize
FillStyle = 0
FillColor = QBColor(ccolor)
'dibuja una circunferencia
Circle (x, y), r, QBColor(color)
End Sub
Private Sub Command8_Click() 'Botn Puntos
Randomize
x = Fix(Me.ScaleWidth * Rnd)
y = Fix(Me.ScaleHeight * Rnd)
color = Fix(16 * Rnd)
PSet (x, y), QBColor(color) 'Dibuja Puntos
End Sub
Para dibujar las Rectas debemos indicarle dos valores de: x, e y para
uno de los puntos extremos y x1, Y1 para el otro luego con el
mtodo Line dibuja una recta que une ambos puntos. Cuando dibuja
un rectngulo. Tambin necesita estos valores pero para dibujar dos
lneas rectas que luego repite en espejo para formar una Box o Caja,
y as aparece el cuadrado o rectngulo. Cuandoq uqeremos que ese
rectngulo este relleno la indicacin ser BF o sea Box Fill, o Caja
rellena. Para esto la propiedad FillStyle debe estar a True. Y con el
Crculo necesitamos un valor para x, y otro para y para establecer un
punto que ser el centro de la circunferencia y un valor para el radio.
Para determinar los colores lo hacemos usando un Randome y la
funcin QBColor. El ejercicio completo puede bajarse de Aqu.
El cdigo es el siguiente:
Usamos la API de Windows sndPlaySound para activar el sonido.
Pueden copiarla de aqu textualmente o convocarla desde el Visor de
las API de Visual Basic.
Private Declare Function sndPlaySound Lib "winmm.dll" Alias
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As
Long) As Long
Const SND_ASYNC = &H1 ' reproduccin asncrona
Option Explicit
Dim snd As Integer
Dim a As Integer
Dim n1 As Integer
Dim n2 As Integer
Dim n3 As Integer
Private Sub Command1_DragOver(Source As Control, X As Single, Y
As Single, State As Integer)
'Dragea la moneda sobre el botn Apostar
Source.Visible = False
Command2.Enabled = True 'habilita el Botn Jugar
End Sub
Image1.Picture = Picture1(0).Picture
Image2.Picture = Picture1(1).Picture
Image3.Picture = Picture1(2).Picture
End If
If a = 2 Then
Image1.Picture = Picture1(1).Picture
Image2.Picture = Picture1(2).Picture
Image3.Picture = Picture1(0).Picture
End If
If a = 3 Then
Image1.Picture = Picture1(2).Picture
Image2.Picture = Picture1(0).Picture
Image3.Picture = Picture1(1).Picture
a=0
End If
End Sub
Private Sub azar()
'Procedimiento que elige tres nmeros al azar correspondientes a
cada 'imagen
n1 = Int(Rnd * 3) + 1
n2 = Int(Rnd * 3) + 1
n3 = Int(Rnd * 3) + 1
Timer1.Enabled = False
Select Case n1
Case 1
Image1.Picture = Picture1(0).Picture
Case 2
Image1.Picture = Picture1(1).Picture
Case 3
Image1.Picture = Picture1(2).Picture
End Select
n1 = n1
Select Case n2
Case 1
Image2.Picture = Picture1(0).Picture
Case 2
Image2.Picture = Picture1(1).Picture
Case 3
Image2.Picture = Picture1(2).Picture
End Select
n2 = n2
Select Case n3
Case 1
Image3.Picture = Picture1(0).Picture
Case 2
Image3.Picture = Picture1(1).Picture
Case 3
Image3.Picture = Picture1(2).Picture
End Select
n3 = n3
'Llama al procedimiento que controla si los tres numeros elegidos al
azar son iguales.
Call ganar
End Sub
Private Sub ganar()
'Procedimiento que controla si los tres nmeros al azar son iguales
gan, sino perdi
Dim m As Integer
If n1 = n2 And n2 = n3 Then Label1.Caption = "Ganaste!!"
snd = sndPlaySound(App.Path & "\Cash2.wav", SND_ASYNC)
For m = 0 To 6
Image4(m).Visible = True
Next m
Else
Label1.Caption = "Perdiste!!"
snd = sndPlaySound(App.Path & "\NoTiempo.wav", SND_ASYNC)
End If
'llama al procedimiento que controla si se termin el dinero.
Call dinero
End Sub
Private Sub dinero()
' Procedimiento que Controla si se acab el dinero
If Image4(0).Visible = False And Image4(1).Visible = False And_
Image4(2).Visible = False And Image4(3).Visible = False And_
Image4(4).Visible = False And Image4(5).Visible = False And_
Image4(5).Visible = False Then
End
End Sub
Private Sub Form_DblClick()
puntero = ShowCursor(-1)
End
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
puntero = ShowCursor(-1)
End
End Sub
Private Sub Form_Load()
If App.PrevInstance Then
End
puntero = ShowCursor(0)
movimiento = 3
End Sub
Private Sub
Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y
As Single)
Static X1 As Integer, Y1 As Integer
If X1 = 0 And Y1 = 0 Then
X1 = x
Y1 = y
Exit Sub
End If
End Sub
Private Sub
Label1_Click()
If MouseIcon = Picture1.Picture Then ' si el puntero es el lpiz la label
'muestra la palabra Tarea en su caption.
Label1.Caption = "Tarea"
End If
If MouseIcon = Picture2.Picture Then ' si el puntero es la goma borra
Tarea.
Label1.Caption = ""
Label1.BackColor = vbYellow ' fondo de la label amarillo
End If
If MouseIcon = Picture3.Picture Then ' si el puntero es el marcador el
fondo se vuelve 'rojo
Label1.Caption = ""
Label1.BackColor = VBred
End If
End Sub
Private Sub Picture1_Click()'carga el icono del lpiz
MouseIcon = Picture1.Picture
MousePointer = 99
Picture1.Visible = False
End Sub
Private Sub Picture2_Click()'carga el icono en el puntero de la goma
MouseIcon = Picture2.Picture
MousePointer = 99
Picture2.Visible = False
End Sub
Private Sub Picture3_Click()'carga el icono en el puntero del
marcador MouseIcon = Picture3.Picture
MousePointer = 99
Picture3.Visible = False
End Sub
El cdigo del ejercicio lo podes bajar de Aqu.
Option Explicit
Dim paso As Integer
Dim i As Integer
Dim tramo1 As String
Dim tramo2 As String
Dim tramo3 As String
Dim tramo4 As String
Private Sub Label1_Click()
Label1.Tag = "si"
Label2.Tag = "no"
Label3.Tag = "no"
Label6.Caption = "A: 500 mts."
Label7.Caption = "B: 500 mts. al Oeste"
Label8.Caption = "C: 4000 mts."
Label9.Caption = "D: 1000 mts."
Timer1.Enabled = True
End Sub
Private Sub Label6_Click()
If Label1.Tag = "si" Then
Label5.Caption = "La respuesta Correcta es la C, porque la distancia
total recorrida es de 4000 mts."
Label5.Visible = True
End If
End Sub
Private Sub
Label7_Click()
If Label1.Tag = "si" Then
Label5.Caption = "La respuesta Correcta es la C, porque la distancia
total recorrida es de 4000 mts."
Label5.Visible = True
End If
End Sub
Private Sub Label8_Click()
If Label1.Tag = "si" Then
Label5.Caption = "La respuesta Correcta es la C, porque la distancia
Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias
"sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As
Long) As Long
Const SND_ASYNC = &H1 ' play asynchronously
Dim sonido As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim f As Integer
Dim g As Integer
Dim h As Integer
Dim i As Integer
Dim j As Integer
Dim patos As Integer
Dim patosin As Integer
Dim patosout As Integer
Private Sub Form_Load()
Randomize
End Sub
Private Sub mniDa_Click()
mniDa.Checked = True
mnuNoche.Checked = False
Form1.Picture = Image1.Picture
Timer1.Enabled = True
Timer3.Enabled = True
Timer5.Enabled = True
Timer7.Enabled = True
Timer9.Enabled = True
Timer4.Enabled = False
Timer2.Enabled = False
Timer6.Enabled = False
Timer8.Enabled = False
Timer10.Enabled = False
Picture6.Visible = False
Picture7.Visible = False
Picture1.Visible = False
Picture8.Visible = False
Picture9.Visible = False
End Sub Private Sub mnuNoche_Click()
mniDa.Checked = False
mnuNoche.Checked = True
Form1.Picture = Image2.Picture
Timer2.Enabled = True
Timer4.Enabled = True
Timer6.Enabled = True
Timer8.Enabled = True
Timer10.Enabled = True
Timer1.Enabled = False
Timer3.Enabled = False
Timer5.Enabled = False
Timer7.Enabled = False
Timer9.Enabled = False
Picture6.Visible = False
Picture7.Visible = False
Picture1.Visible = False
Picture8.Visible = False
Picture9.Visible = False
End Sub
Private Sub mnuNuevo_Click()
Picture1.Left = 0
Picture1.Top = 480
Picture6.Left = 1560
Picture6.Top = 1440
Picture7.Left = 480
Picture7.Top = 2760
Picture8.Left = 2400
Picture8.Top = 240
Picture9.Left = 2880
Picture9.Top = 2160
Picture1.Visible = True
Picture8.Visible = True
Picture6.Visible = True
If mniDa.Checked = True Then
Timer1.Enabled = True
Timer3.Enabled = True
Timer5.Enabled = True
Timer7.Enabled = True
Timer9.Enabled = True
ElseIf mnuNoche.Checked = True Then
Timer2.Enabled = True
Timer4.Enabled = True
Timer6.Enabled = True
Timer8.Enabled = True
Timer10.Enabled = True
End If
End Sub
Private Sub mnuSalir_Click()
End
End Sub
Private Sub Picture1_Click()
sonido = sndPlaySound(App.Path & "\shoot.wav", SND_ASYNC)
If Timer1.Enabled = True Then
Timer1.Enabled = False
Picture1.Picture = Picture3.Picture
Call pausa
Picture1.Visible = False
patosin = patosin + 1
Call final
Picture1.Picture = Picture2(0).Picture
ElseIf Timer2.Enabled = True Then
Timer2.Enabled = False
Picture1.Picture = Picture5.Picture
Call pausa
Picture1.Visible = False
patosin = patosin + 1
Call final
Picture1.Picture = Picture4(0).Picture
End If
End Sub
Private Sub Picture6_Click()
sonido = sndPlaySound(App.Path & "\shoot.wav", SND_ASYNC)
If Timer5.Enabled = True Then
Timer5.Enabled = False
Picture6.Picture = Picture3.Picture
Call pausa
Picture6.Visible = False
patosin = patosin + 1
Call final
Picture6.Picture = Picture2(0).Picture
ElseIf Timer6.Enabled = True Then
Timer6.Enabled = False
Picture6.Picture = Picture5.Picture
Call pausa
Picture6.Visible = False
patosin = patosin + 1
Call final
Picture6.Picture = Picture4(0).Picture
End If
End Sub
Private Sub Picture7_Click()
sonido = sndPlaySound(App.Path & "\shoot.wav", SND_ASYNC)
If Timer9.Enabled = True Then
Timer9.Enabled = False
Picture7.Picture = Picture3.Picture
Call pausa
Picture7.Visible = False
patosin = patosin + 1
Call final
Picture7.Picture = Picture2(0).Picture
ElseIf Timer10.Enabled = True Then
Timer10.Enabled = False
Picture7.Picture = Picture5.Picture
Call pausa
Picture7.Visible = False
patosin = patosin + 1
Call final
Picture7.Picture = Picture4(0).Picture
End If
End Sub
Private Sub Picture8_Click()
sonido = sndPlaySound(App.Path & "\shoot.wav", SND_ASYNC)
If Timer3.Enabled = True Then
Timer3.Enabled = False
Picture8.Picture = Picture3.Picture
Call pausa
Picture8.Visible = False
patosin = patosin + 1
Call final
Picture8.Picture = Picture2(0).Picture
ElseIf Timer4.Enabled = True Then
Timer4.Enabled = False
Picture8.Picture = Picture5.Picture
Call pausa
Picture8.Visible = False
patosin = patosin + 1
Call final
Picture8.Picture = Picture4(0).Picture
End If
End Sub
Private Sub Picture9_Click()
sonido = sndPlaySound(App.Path & "\shoot.wav", SND_ASYNC)
If Timer7.Enabled = True Then
Timer7.Enabled = False
Picture9.Picture = Picture3.Picture
Call pausa
Picture9.Visible = False
patosin = patosin + 1
Call final
Picture9.Picture = Picture2(0).Picture
ElseIf Timer8.Enabled = True Then
Timer8.Enabled = False
Picture9.Picture = Picture5.Picture
Call pausa
Picture9.Visible = False patosin = patosin + 1
Call final
Picture9.Picture = Picture4(0).Picture
End If
End Sub
Private Sub Timer1_Timer()
a=a+1
If a = 3 Then
a=0
Picture1.Picture = Picture2(a).Picture
Picture1.Visible = True
Dim r As Integer
r = Int(Rnd * 20)
Picture1.Move Picture1.Left + 200, Picture1.Top + r
End Sub
Private SubTimer10_Timer()
j = j + 1 If j = 3 Then
j=0
Picture7.Picture = Picture4(c).Picture
Picture7.Visible = True
Dim r As Integer
r = Int(Rnd * 30)
Picture7.Move Picture7.Left + 200, Picture7.Top - r
End Sub
Private Sub Timer2_Timer()
b = b + 1 If b = 3 Then b = 0
Picture1.Picture = Picture4(b).Picture
Picture1.Visible = True
Dim r As Integer
r = Int(Rnd * 20)
Picture1.Move Picture1.Left + 200, Picture1.Top + r
End Sub
Private Sub pausa()
Dim comenzar
Dim controlar
comenzar = Timer
Do Until controlar >= comenzar + 0.3
controlar = Timer
DoEvents
Loop
End Sub
f=f+1
If f = 3 Then
f=0
Picture6.Picture = Picture4(c).Picture
Picture6.Visible = True
Picture6.Move Picture6.Left + 200, Picture6.Top
End Sub
Private Sub Timer7_Timer()
g=g+1
If g = 3 Then
g=0
Picture9.Picture = Picture2(c).Picture
Picture9.Visible = True
Dim r As Integer
r = Int(Rnd * 30)
Picture9.Move Picture9.Left + 200, Picture9.Top - r
End Sub
Private Sub Timer8_Timer()
h=h+1
If h = 3 Then
h=0
Picture9.Picture = Picture4(c).Picture
Picture9.Visible = True
Dim r As Integer
r = Int(Rnd * 30)
Picture9.Move Picture9.Left + 200, Picture9.Top - r
End Sub
Private Sub Timer9_Timer()
i=i+1
If i = 3 Then
i=0
Picture7.Picture = Picture2(c).Picture
Picture7.Visible = True
Dim r As Integer
r = Int(Rnd * 30)
Picture7.Move Picture7.Left + 200, Picture7.Top - r
End Sub
Private Sub final()
Label1.Caption = " Cazaste: " & patosin
If patosin = 10 Then
Form2.Label1.Caption = " Felicitaciones !!! Eres un Buen Cazador."
sonido = sndPlaySound(App.Path & "\clarin.wav", SND_ASYNC)
Form2.Show 1
ElseIf patosin = 20 Then
Form2.Label1.Caption = " Felicitaciones !!! Eres un Muy Buen
Cazador."
sonido = sndPlaySound(App.Path & "\clarin.wav", SND_ASYNC)
Form2.Show 1
ElseIf patosin = 50 Then
Option Explicit
Private Sub pausa()
Dim comenzar
Dim controlar
comenzar = Timer
Do Until controlar >= comenzar + 2
controlar = Timer
DoEvents
Loop
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub Timer1_Timer()
Picture1.Move Picture1.Left, Picture1.Top + 150
'con el condicional controla el reposicionarse.
If Picture1.Top > 7000 Then
Picture1.Top = -300
Picture2.Move Picture2.Left, Picture2.Top + 150
If Picture2.Top > 6500 Then
Picture2.Top = -200 Picture4.Move
Picture4.Left, Picture4.Top + 150
If Picture4.Top > 6500 Then
Picture4.Top = -100 Picture5.Move
Picture5.Left, Picture5.Top + 150
If Picture5.Top > 6500 Then
Picture5.Top = -100
Picture9.Move Picture9.Left, Picture9.Top + 150
Picture5.Top = 1680
Picture5.Visible = True
Picture9.Top = 120
Picture9.Visible = True
Picture10.Top = 0
Picture10.Visible = True
Picture11.Top = 4200
Picture11.Visible = True
Picture12.Top = 4440
Picture12.Visible = True
Call pausa
Picture3.Picture = Picture8.Picture
Timer1.Interval = 150
Call pausa
End Sub
Private Sub Timer3_Timer()
Image1.Move Image1.Left + 100
End Sub
El cdigo completo puede bajarse de Aqu.
Call pausa
Label5.Visible = True
End Sub
El cdigo puede bajarse de Aqu.
Option Explicit
Dim imagen As Integer
Dim Moviendo As Boolean
'Aqu establecemos las constantes de mximo y mnimo
Const MaxSlider1 = 6
Const MinSlider1 = 1
Private Sub Form_Load()
Moviendo = False
lblMin = MinSlider1
lblMax = MaxSlider1
lblValor = MinSlider1
End Sub
Private Sub imgPuntero_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Dim Cursor As POINTAPI
Dim Anterior As Long
Do 'Para que no lo actualize si no cambio
Anterior = Cursor.X
Moviendo = True
'Cargo la posicion del mouse
Call GetCursorPos(Cursor)
Cursor.X = Cursor.X - (Form1.Left / Screen.TwipsPerPixelX) imgPuntero.Width
'Si no cambio, y no sale de los bordes de la barra, entonces...
If (Anterior <> Cursor.X) And (Cursor.X >= imgBarra.Left) And
(Cursor.X + imgPuntero.Width <= imgBarra.Left + imgBarra.Width)
Then
imgPuntero.Left = Cursor.X
End If
lblValor = Int((imgPuntero.Left - imgBarra.Left) * (MaxSlider1 MinSlider1) / (imgBarra.Width - imgPuntero.Width)) + MinSlider1
Call mostrar
'Que haga los eventos para ver si hay MouseUp
DoEvents
Loop Until
Moviendo = False
End
Sub Private Sub imgPuntero_MouseUp(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Moviendo = False
End Sub
Private Sub mostrar() If lblValor = 1 Then
Picture1.Picture = Image1(0).Picture
ElseIf lblValor = 3 Then
Picture1.Picture = Image1(1).Picture
Option Explicit
Private Sub Slider1_Change()
Label1.Caption = "Medida en Centmetros = " & Format(Slider1.Value,
"#.00")
End Sub
Private Sub Slider1_Scroll()
Label1.Caption = "Medida en Centmetros = " & Format(Slider1.Value,
"#.00")
End Sub
El cdigo puede bajarse desde AQU.
Los controles que usamos son: un Media palyer, los tres controles
tipicos para manipular archivos : DriveListBox, el DirListBox y el
FileListBox, dos botones y dos labels con un timer que daran cuenta
del tiempo total y parcial del archivo. El cdigo es:
Option Explicit
Dim Min As Integer
Dim Sec As Integer
Dim Nombrearchivo As String
Dim Abrirarchivo As Boolean
End Sub
El cdigo es:
Option Explicit
Private Sub Command1_Click()'boton de nmero al azar
Dim azar As Integer
Randomize
azar = Int(10 * Rnd) + 1
Label3.Caption = azar
End Sub
Private Sub Command2_Click()'nmero al azar entre dos valores
Dim azar As Integer
Dim rangomenor As Integer
Dim rangomayor As Integer
Randomize
rangomayor = CInt(Text2)
rangomenor = CInt(Text1)
azar = Int((rangomayor - rangomenor + 1) * Rnd + rangomenor)
Label4 = azar
End Sub
Private Sub Command3_Click()' raz de un nmero
Dim numero As Integer
Dim raiz As Integer
raiz = CInt(Text3)
numero = CInt(Text4)
Label5.Caption = numero ^ (1 / raiz)
End Sub
Private Sub Command4_Click()'redondeo de un decimal
Dim numero
Dim decimales As Integer
numero = Text6
decimales = CInt(Text5)
Label10.Caption = Round(numero, decimales)
End Sub
Private Sub Form_Activate()
Text1.SetFocus
End Sub
End Sub
Function InteresCompuesto(capital As Currency, interesmensual As
Single, cuotas As Long) As Currency
Dim i As Long
Dim total As Currency
total = capital
For i = 1 To cuotas
total = total + (total * (interesmensual))
Next i
InteresCompuesto = total - capital
End Function
Los ejercicios con su cdigo completo pueden bajarse de AQU.
lblRespuesta.ZOrder 0
lblRespuesta.Caption = "Muy bien resuelta la Tabla! FELICIDADES!"
End If
End Sub
Private Sub AniPushButton1_Click()
frmTablaDel_1.Hide
frmTablaSumaDel_2.Show
End Sub
Private Sub AniPushButton2_Click()
'Limpiar los resultados
img0.Picture = LoadPicture("")
img1.Picture = LoadPicture("")
img2.Picture = LoadPicture("")
img3.Picture = LoadPicture("")
img4.Picture = LoadPicture("")
img5.Picture = LoadPicture("")
img6.Picture = LoadPicture("")
img7.Picture = LoadPicture("")
img8.Picture = LoadPicture("")
img9.Picture = LoadPicture("")
'Poner los nmeros en la bola
ImageUno.Visible = True
ImageDos.Visible = True
ImageTres.Visible = True
ImageCuatro.Visible = True
ImageCinco.Visible = True
ImageSeis.Visible = True
ImageSiete.Visible = True
ImageOcho.Visible = True
ImageNueve.Visible = True
ImageCero.Visible = True
'Inicializar la propiedad Tag
img0.Tag = "vacia"
img1.Tag = "vacia"
img2.Tag = "vacia"
img2.Tag = "vacia"
img4.Tag = "vacia"
img5.Tag = "vacia"
img6.Tag = "vacia"
img7.Tag = "vacia"
img8.Tag = "vacia"
img9.Tag = "vacia"
'Limpiar los CheckBox y la imagenes
Check1.Caption = ""
Check1.Visible = False
imgConejo.Visible = False
Check2.Caption = ""
Check2.Value = 0
imgOsito.Visible = False
Check3.Caption = ""
Check3.Value = 0
imgPato.Visible = False
Check4.Caption = ""
Check4.Value = 0
imgGato.Visible = False
Check5.Caption = ""
Check5.Value = 0
imgBug.Visible = False
Check6.Caption = ""
Check6.Value = 0
imgNia.Visible = False
Check7.Caption = ""
Check7.Value = 0
imgOso.Visible = False
Check8.Caption = ""
Check8.Value = 0
imgAlce.Visible = False
Check9.Caption = ""
Check9.Value = 0
imgViejito.Visible = False
lblRespuesta.ZOrder 1 'pasar atrs el label
End Sub
Private Sub Check1_Click()
Check1.Value = 1
End Sub
Private Sub Check2_Click()
Check2.Value = 1
End Sub
Private Sub Check3_Click()
Check3.Value = 1
End Sub
Private Sub Check4_Click()
Check4.Value = 1
End Sub
img7.Tag = "vacia"
img8.Tag = "vacia"
img9.Tag = "vacia"
'Limpiar los CheckBox y la imagenes
Check1.Caption = ""
Check1.Value = 0
imgConejo.Visible = False
Check2.Caption = ""
Check2.Value = 0
imgOsito.Visible = False
Check3.Caption = ""
Check3.Value = 0
imgPato.Visible = False
Check4.Caption = ""
Check4.Value = 0
imgGato.Visible = False
Check5.Caption = ""
Check5.Value = 0
imgBug.Visible = False
Check6.Caption = ""
Check6.Value = 0
imgNia.Visible = False
Check7.Caption = ""
Check7.Value = 0
imgOso.Visible = False
Check8.Caption = ""
Check8.Value = 0
imgAlce.Visible = False
Check9.Caption = ""
Check9.Value = 0
imgViejito.Visible = False
lblRespuesta.ZOrder 1 'pasar atrs el label
End Sub
Private Sub img0_DragDrop(Source As Control, X As Single, Y As
Single)
flag2 = 2
If TypeOf Source Is Image Then
If img0.Tag = "vacia" And Source.Tag = "cero" Then
img0.Picture = LoadPicture(App.Path & "\#0.ico")
img0.Tag = "Correcta"
Source.Visible = False
If flag1 = 1 And flag2 = 2 Then 'Chequea si estan colocados los dos
numeros
Check9.Caption = "Correcta"
Check9.Value = 1
imgViejito.Visible = True
End If
For I = 1 To 20
Beep
Next I
Call ganar
ElseIf img0.Tag = "vacia" And Source.Tag <> "cero" Then
MsgBox "Esa suma es incorrecta", vbCritical
End If
End If
End Sub
Private Sub img1_DragDrop(Source As Control, X As Single, Y As
Single)
If TypeOf Source Is Image Then
If img1.Tag = "vacia" And Source.Tag = "dos" Then
img1.Picture = LoadPicture(App.Path & "\#2.ico")
img1.Tag = "Correcta"
Source.Visible = False
Check1.Caption = "Correcta"
Check1.Value = 1
Check1.Visible = True
imgConejo.Visible = True
For I = 1 To 20
Beep
Next I
Call ganar
ElseIf img1.Tag = "vacia" And Source.Tag <> "dos" Then
MsgBox "Esa suma es incorrecta"
End If
End If
End Sub
Private Sub img2_DragDrop(Source As Control, X As Single, Y As
Single)
If TypeOf Source Is Image Then
If img2.Tag = "vacia" And Source.Tag = "tres" Then
img2.Picture = LoadPicture(App.Path & "\#3.ico")
img2.Tag = "Correcta"
Source.Visible = False
Check2.Caption = "Correcta"
Check2.Value = 1
imgOsito.Visible = True
For I = 1 To 20
Beep
Next I
Call ganar
ElseIf img2.Tag = "vacia" And Source.Tag <> "tres" Then
MsgBox "Esa suma es incorrecta", vbCritical
End If
End If
End Sub
Private Sub img3_DragDrop(Source As Control, X As Single, Y As
Single)
If TypeOf Source Is Image Then
If img3.Tag = "vacia" And Source.Tag = "cuatro" Then
img3.Picture = LoadPicture(App.Path & "\#4.ico")
img3.Tag = "Correcta"
Source.Visible = False
Check3.Caption = "Correcta"
Check3.Value = 1
imgPato.Visible = True
For I = 1 To 20
Beep
Next I
Call ganar
ElseIf img3.Tag = "vacia" And Source.Tag <> "cuatro" Then
MsgBox "Esa suma es incorrecta", vbCritical
End If
End If
End Sub
Private Sub img4_DragDrop(Source As Control, X As Single, Y As
Single)
If TypeOf Source Is Image Then
If img4.Tag = "vacia" And Source.Tag = "cinco" Then
img4.Picture = LoadPicture(App.Path & "\#5.ico")
img4.Tag = "Correcta"
Source.Visible = False
Check4.Caption = "Correcta"
Check4.Value = 1
imgGato.Visible = True
For I = 1 To 20
Beep
Next I
Call ganar
ElseIf img4.Tag = "vacia" And Source.Tag <> "cinco" Then
MsgBox "Esa suma es incorrecta", vbCritical
End If
End If
End Sub
Private Sub img5_DragDrop(Source As Control, X As Single, Y As
Single)
If TypeOf Source Is Image Then
If img5.Tag = "vacia" And Source.Tag = "seis" Then
img5.Picture = LoadPicture(App.Path & "\#6.ico")
img5.Tag = "Correcta"
Source.Visible = False
Check5.Caption = "Correcta"
Check5.Value = 1
imgBug.Visible = True
For I = 1 To 20
Beep
Next I
Call ganar
ElseIf img5.Tag = "vacia" And Source.Tag <> "seis" Then
MsgBox "Esa suma es incorrecta", vbCritical
End If
End If
End Sub
Private Sub img6_DragDrop(Source As Control, X As Single, Y As
Single)
If TypeOf Source Is Image Then
If img6.Tag = "vacia" And Source.Tag = "siete" Then
img6.Picture = LoadPicture(App.Path & "\#7.ico")
img6.Tag = "Correcta"
Source.Visible = False
Check6.Caption = "Correcta"
Check6.Value = 1
imgNia.Visible = True
For I = 1 To 20
Beep
Next I
Call ganar
ElseIf img6.Tag = "vacia" And Source.Tag <> "siete" Then
MsgBox "Esa suma es incorrecta", vbCritical
End If
End If
End Sub
Private Sub img7_DragDrop(Source As Control, X As Single, Y As
Single)
If TypeOf Source Is Image Then
If img7.Tag = "vacia" And Source.Tag = "ocho" Then
img7.Picture = LoadPicture(App.Path & "\#8.ico")
img7.Tag = "Correcta"
Source.Visible = False
Check7.Caption = "Correcta"
Check7.Value = 1
imgOso.Visible = True
For I = 1 To 20
Beep
Next I
Call ganar
ElseIf img7.Tag = "vacia" And Source.Tag <> "ocho" Then
MsgBox "Esa suma es incorrecta", vbCritical
End If
End If
End Sub
End If
End Sub
Private Sub Text1_Click()
'Para marcar el texto
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
El ejercicio con su cdigo completo puede bajarse de AQU.
End Sub
Private Sub Form_Load()
'Inicializar las variables
a=1
b=2
c=1
'Inicializar las cajas de texto
txtA.Text = a
txtB.Text = b
txtC.Text = c
End Sub
Private Sub mnuAbrir_Click()
Dim Fichero As String 'Variable para el nombre del Fichero
CommonDialog1.Action = 1 'Ventana Abrir
Fichero = CommonDialog1.FileName
If Fichero = "" Then Exit Sub
Open Fichero For Random As #1 'Abrir el Fichero
'Tomar los valores del Fichero
Get #1, 1, a
Get #1, 2, b
Get #1, 3, c
Get #1, 4, x1
Get #1, 5, x2
Close #1
'Asignar los valores a las cajas de texto.
txtA.Text = a
txtB.Text = b
txtC.Text = c
cmdCalcular_Click 'Mandar a calcular
End Sub
Private Sub mnuSalvar_Click()
Dim Fichero As String
If Fichero = "" Then
mnuSalvarComo_Click
Exit Sub
End If
Open Fichero For Random As #1 'Abrir el Fichero.
'Guardar el valor de las variables en el Fichero.
Put #1, , a
Put #1, , b
Put #1, , c
Put #1, , x1
Put #1, , x2
Close (1)
End Sub
Private Sub mnuSalvarComo_Click()
Dim Fichero As String
CommonDialog1.Action = 2 'Abrir la ventana Salvar como.
Fichero = CommonDialog1.FileName
txtX2.Text = ""
End Sub
Private Sub txtC_GotFocus()
txtC.SelStart = 0
txtC.SelLength = Len(txtC.Text)
End Sub
Private Sub txtC_LostFocus()
If IsNumeric(txtC.Text) Then
c = txtC.Text
Else
MsgBox "Valor incorrecto", vbInformation
txtC.SetFocus
End If
End Sub
El ejercicio con su cdigo completo puede bajarse de AQU.
End Sub
Private Sub optPedido1_Click()
'Hamburguesas,Gaseosa y Papas Fritas.
'Limpiar el label lblTotal.
lblTotal.Caption = ""
If optPedido1.Value Then 'si esta chequeado.
'Inicializar las variables.
CantidadHamburguesa = 1
CantidadGaseosa = 1
CantidadPapasFritas = 1
CantidadHotDog = 0
CantidadSandwich = 0
CantidadRefresco = 0
'Inicializar la caja de texto.
txtHamburguesa.Text = CantidadHamburguesa
txtGaseosa.Text = CantidadGaseosa
txtPapasFritas.Text = CantidadPapasFritas
'Habilitar las cajas de texto.
txtHamburguesa.Enabled = True
txtGaseosa.Enabled = True
txtPapasFritas.Enabled = True
'Deshabilitar las otras cajas de texto.
txtHotDog.Enabled = False
txtSandwich.Enabled = False
txtRefresco.Enabled = False
'Limpiar las otras cajas de texto.
txtHotDog.Text = ""
txtSandwich.Text = ""
txtRefresco.Text = ""
End If
End Sub
Private Sub optPedido2_Click()
'HotDog,Gaseosa y Papas Fritas.
'Limpiar el label lblTotal.
lblTotal.Caption = ""
If optPedido2.Value Then
'Inicializar las variables.
CantidadHotDog = 1
CantidadGaseosa = 1
CantidadPapasFritas = 1
CantidadHamburguesa = 0
CantidadSandwich = 0
CantidadRefresco = 0
'Inicializar la caja de texto.
txtHotDog.Text = CantidadHotDog
txtGaseosa.Text = CantidadGaseosa
txtPapasFritas.Text = CantidadPapasFritas
'Habilitar las cajas de texto.
txtHotDog.Enabled = True
txtGaseosa.Enabled = True
txtPapasFritas.Enabled = True
'Deshabilitar las otras cajas de texto.
txtHamburguesa.Enabled = False
txtSandwich.Text = False
txtRefresco.Text = False
'Limpiar las otras cajas de texto.
txtHamburguesa.Text = ""
txtSandwich.Text = ""
txtRefresco.Text = ""
End If
End Sub
Private Sub optPedido3_Click()
'Sanwich,Gaseosa y Papas Fritas.
'Limpiar el label lblTotal
lblTotal.Caption = ""
If optPedido3.Value Then
'Inicializar las variables
CantidadSandwich = 1
CantidadGaseosa = 1
CantidadPapasFritas = 1
CantidadHamburguesa = 0
CantidadHotDog = 0
CantidadRefresco = 0
'Inicializar la caja de texto
txtSandwich.Text = CantidadSandwich
txtGaseosa.Text = CantidadGaseosa
txtPapasFritas.Text = CantidadPapasFritas
'Habilitar las cajas de texto
txtSandwich.Enabled = True
txtGaseosa.Enabled = True
txtPapasFritas.Enabled = True
'Deshabilitar las otras cajas de texto.
txtHotDog.Enabled = False
txtHamburguesa.Enabled = False
txtRefresco.Enabled = False
'Limpiar las otras cajas de texto.
txtHotDog.Text = ""
txtHamburguesa.Text = ""
txtRefresco.Text = ""
End If
End Sub
Private Sub txtHamburguesa_Change()
'Limpiando el lblTotal.
lblTotal.Caption = ""
End Sub
Private Sub txtHamburguesa_GotFocus()
txtHamburguesa.SelStart = 0
txtHamburguesa.SelLength = Len(txtHamburguesa.Text)
End Sub
Private Sub txtHamburguesa_LostFocus()
If txtHamburguesa.Text = "" Then
CantidadHamburguesa = 0
Exit Sub
End If
If IsNumeric(txtHamburguesa.Text) Then 'Si es numrico.
If txtHamburguesa.Text > 0 Then 'Si es positivo.
CantidadHamburguesa = txtHamburguesa.Text 'Entonces asigna el
valor a la variable.
Else
MsgBox "Entre un valor positivo", vbCritical
txtHamburguesa.SetFocus
End If
Else
MsgBox "Entre un valor numrico", vbCritical
txtHamburguesa.SetFocus
End If
End Sub
Private Sub txtGaseosa_Change()
lblTotal.Caption = ""
End Sub
Private Sub txtGaseosa_GotFocus()
'Para seleccionar el texto(igual en todos).
txtGaseosa.SelStart = 0
txtGaseosa.SelLength = Len(txtGaseosa.Text)
End Sub
Private Sub txtGaseosa_LostFocus()
If txtGaseosa.Text = "" Then
CantidadGaseosa = 0
Exit Sub
End If
If IsNumeric(txtGaseosa.Text) Then 'Si es numrico.
If txtGaseosa.Text > 0 Then 'Si es positivo.
CantidadGaseosa = txtGaseosa.Text 'Entonces asigna el valor a la
variable.
Else
MsgBox "Entre un valor positivo", vbCritical
txtGaseosa.SetFocus
End If
Else
MsgBox "Entre un valor numrico", vbCritical
txtGaseosa.SetFocus
End If
End Sub
Private Sub txtHotDog_Change()
lblTotal.Caption = ""
End Sub
Private Sub txtHotDog_GotFocus()
txtHotDog.SelStart = 0
txtHotDog.SelLength = Len(txtHotDog.Text)
End Sub
Private Sub txtHotDog_LostFocus()
If txtHotDog.Text = "" Then
CantidadHotDog = 0
Exit Sub
End If
If IsNumeric(txtHotDog.Text) Then 'Si es numrico.
If txtHotDog.Text > 0 Then 'Si es positivo.
CantidadHotDog = txtHotDog.Text 'Entonces asigna el valor a la
variable.
Else
MsgBox "Entre un valor positivo", vbCritical
txtHotDog.SetFocus
End If
Else
MsgBox "Entre un valor numrico", vbCritical
txtHotDog.SetFocus
End If
End Sub
Private Sub txtPapasFritas_Change()
lblTotal.Caption = ""
End Sub
Private Sub txtPapasFritas_GotFocus()
txtPapasFritas.SelStart = 0
txtPapasFritas.SelLength = Len(txtPapasFritas.Text)
End Sub
Private Sub txtPapasFritas_LostFocus()
If txtPapasFritas.Text = "" Then
CantidadPapasFritas = 0
Exit Sub
End If
If IsNumeric(txtPapasFritas.Text) Then 'Si es numrico.
If txtPapasFritas.Text > 0 Then 'Si es positivo.
CantidadPapasFritas = txtPapasFritas.Text 'Entonces asigna el valor
a la variable.
Else
MsgBox "Entre un valor positivo", vbCritical
txtPapasFritas.SetFocus
End If
Else
MsgBox "Entre un valor numrico", vbCritical
txtPapasFritas.SetFocus
End If
End Sub
Private Sub txtRefresco_Change()
lblTotal.Caption = ""
End Sub
Private Sub txtRefresco_GotFocus()
txtRefresco.SelStart = 0
txtRefresco.SelLength = Len(txtRefresco.Text)
End Sub
Private Sub txtRefresco_LostFocus()
If txtRefresco.Text = "" Then
CantidadRefresco = 0
Exit Sub
End If
If IsNumeric(txtRefresco.Text) Then 'Si es numrico.
If txtRefresco.Text > 0 Then 'Si es positivo.
CantidadRefresco = txtRefresco.Text 'Entonces asigna el valor a la
variable.
Else
MsgBox "Entre un valor positivo", vbCritical
txtRefresco.SetFocus
End If
Else
MsgBox "Entre un valor numrico", vbCritical
txtRefresco.SetFocus
End If
End Sub
Private Sub txtSandwich_Change()
lblTotal.Caption = ""
End Sub
Private Sub txtSandwich_GotFocus()
txtSandwich.SelStart = 0
txtSandwich.SelLength = Len(txtSandwich.Text)
End Sub
Private Sub txtSandwich_LostFocus()
If txtSandwich.Text = "" Then
CantidadSandwich = 0
Exit Sub
End If
If IsNumeric(txtSandwich.Text) Then 'Si es numrico.
End Sub
Private Sub Label3_Click()
End
End Sub
El ejercicio con su cdigo completo puede bajarse de Aqu
Option Explicit
Dim Figura As String 'Identifica las figuras.
Dim B1 As Single 'Para la base mayor del trapecio.
Dim b As Single 'Para la base.
Dim h As Single 'Para la altura.
Dim Area As Single 'Para el rea
Const Pi = 3.1415 'constante
Sub Circulo()
Call Limpiar
Call OcultarB1 'Pone invisible lblB1 y txtB1 por no necesitarse para
el clculo.
Call OcultarH 'Pone invisible lblH y txtH por no necesitarse para el
clculo.
lblB.Caption = "r="
picFigura.DrawStyle = 0 'Dibujar con lneas continuas.
fraDatos.Visible = True 'MostrarB1 los datos.
fraResultados.Visible = False 'OcultarB1 los resultados.
Dim x As Single, y As Single
x = picFigura.Width / 2
y = picFigura.Height / 2
picFigura.DrawWidth = 2 'Grueso del punto del centro.
picFigura.PSet (x, y) 'Poner un punto en el centro.
picFigura.DrawWidth = 1 'Restaurar el grueso para dibujar el crculo.
picFigura.Circle (x, y), 700 'Dibujar el crculo en el centro del Picture.
'Dibujar el radio.
picFigura.Line (x, y)-(600, 600)
'Colocar los letreros de la base.
picFigura.CurrentX = 1000
picFigura.CurrentY = 600
picFigura.Print "r"
'Situar la frmula.
picFormula.CurrentX = 25
picFormula.CurrentY = 500
picFormula.FontBold = True
picFormula.FontSize = 12
picFormula.Print " rea = 3.14 x r ^ 2 "
End Sub
Sub Trapecio()
Call Limpiar
Call MostrarB1
Call MostrarH
Call CambiarLabels
picFigura.DrawStyle = 0 'Dibujar con lneas continuas.
'Dibuja las 4 lneas.
picFigura.Line (300, 1400)-(300, 300)
picFigura.Line -(1500, 300)
picFigura.Line -(2100, 1400)
picFigura.Line -(300, 1400)
'Colocar los letreros de altura.
picFigura.CurrentX = 100
picFigura.CurrentY = 700
picFigura.Print "h"
'Colocar los letreros de la base mayor.
picFigura.CurrentX = 1100
picFigura.CurrentY = 1450
picFigura.Print "B"
'Colocar los letreros de la base menor.
picFigura.CurrentX = 850
picFigura.CurrentY = 50
picFigura.Print "b"
'Situar la frmula.
picFormula.CurrentX = 50
picFormula.CurrentY = 500
picFormula.FontBold = True
picFormula.FontSize = 12
picFormula.Print "rea = (B + b)h / 2 "
End Sub
Sub CambiarLabels()
lblB.Caption = "b="
lblH.Caption = "h="
End Sub
Sub Rombo()
Call Limpiar
picFigura.DrawStyle = 0 'Dibujar con lneas continuas.
'Dibuja las 4 lneas.
picFigura.Line (500, 850)-(1050, 100)
picFigura.Line -(1700, 850)
picFigura.Line -(1050, 1600)
picFigura.Line -(500, 850)
picFigura.DrawStyle = 2 'Dibujar la diagonales con lneas
discontinuas.
'Dibujar diagonales
picFigura.Line (500, 850)-(1700, 850)
picFigura.Line (1050, 100)-(1050, 1600)
End Sub
Sub MostrarB1() 'Muestra lblB1 y txtB1.
lblB1.Visible = True
txtB1.Visible = True
End Sub
Sub Triangulo()
Call Limpiar
picFigura.DrawStyle = 0 'Dibujar con lneas continuas.
Call CambiarLabels
'Dibuja las 3 lneas.
picFigura.Line (300, 1400)-(1600, 300)
picFigura.Line -(2100, 1400)
picFigura.Line -(300, 1400)
picFigura.DrawStyle = 2 'Dibujar la altura con lneas continuas.
'Dibuja la altura
picFigura.Line (1600, 300)-(1600, 1400)
'Colocar los letreros de altura.
picFigura.CurrentX = 1450
picFigura.CurrentY = 900
picFigura.Print "h"
'Colocar los letreros de la base.
picFigura.CurrentX = 1300
picFigura.CurrentY = 1450
picFigura.Print "b"
'Situar la frmula
picFormula.CurrentX = 100
picFormula.CurrentY = 500
picFormula.FontBold = True
picFormula.FontSize = 12
picFormula.Print " rea=( b x h ) / 2"
End Sub
Private Sub cmdCalcular_Click()
fraResultados.Visible = True
Select Case Figura
Case "Triangulo"
Area = b * h / 2
Case "Paralelogramo"
Area = b * h
Case "Rectangulo"
Area = b * h
Case "Cuadrado"
Area = b ^ 2 'Usamos la misma variable b para el lado.
Case "Rombo"
Area = b * h / 2 'Usamos las mismas variables b y h para las
diagonales.Cambiamos las etiquetas a d1 y d2.
Case "Trapecio"
Area = (B1 + b) * h / 2
Case "Circulo"
Area = Pi * b ^ 2 'Usamos la variable b por el radio.Cambiamos la
etiqueta a r.
End Select
txtArea.Text = Area
End Sub
Private Sub cmdSalir_Click()
End
End Sub
Private Sub Form_Load()
'Inicializar las variables.
h=1
b=2
B1 = 1
'Inicializar las cajas de texto.
txtB.Text = b
txtH.Text = h
txtB1.Text = B1
End Sub
Private Sub optCirculo_Click()
If optCirculo.Value Then
Figura = "Circulo"
Call Circulo 'Dibuja el crculo.
End If
End Sub
Private Sub optCuadrado_Click()
If optCuadrado.Value Then
Figura = "Cuadrado"
Call OcultarB1 'Pone invisible lblB1 y txtB1 por no necesitarse para
el clculo.
Call OcultarH 'Pone invisible lblH y txtH por no necesitarse para el
clculo.
Call Cuadrado 'Dibuja el cuadrado.
fraDatos.Visible = True 'MostrarB1 los datos.
fraResultados.Visible = False 'OcultarB1 los resultados.
End If
End Sub
Private Sub optParalelogramo_Click()
If optParalelogramo.Value Then
Figura = "Paralelogramo"
Call Paralelogramo 'Dibuja el paralelogramo.
Call OcultarB1 'Pone invisible lblB1 y txtB1 por no necesitarse para
el clculo.
Call MostrarH 'Pone visible lblH y txtH.
fraDatos.Visible = True 'MostrarB1 los datos
fraResultados.Visible = False 'OcultarB1 los resultados
End If
End Sub
Private Sub optRectangulo_Click()
If optRectangulo Then
Figura = "Rectangulo"
Call Rectangulo 'Dibuja el rectngulo.
End If
End Sub
Private Sub txtB1_LostFocus()
If IsNumeric(txtB1.Text) Then 'Cheque si el valor es numrico.
If txtB1.Text > 0 Then 'Chequea si es mayor que cero.
B1 = txtB1.Text 'Asigna el valor del texto a la variable.
Else 'Si no cumple lo anterior.
MsgBox "Valor incorrecto,debe ser mayor que cero", vbCritical
txtB1.SetFocus 'Situa el foco en el TexBox txtB1.
End If
Else 'Si no es numrico el dato.
MsgBox "El valor debe ser mayor que cero", vbCritical
txtB1.SetFocus 'Situa el foco en el TexBox txtB1.
End If
End Sub
Private Sub txtH_LostFocus()
If IsNumeric(txtH.Text) Then 'Cheque si el valor es numrico.
If txtH.Text > 0 Then 'Chequea si es mayor que cero.
h = txtH.Text 'Asigna el valor del texto a la variable.
Else 'Si no cumple lo anterior.
MsgBox "Valor incorrecto,debe ser mayor que cero", vbCritical
txtH.SetFocus 'Situa el foco en el TexBox txtH.
End If
Else 'Si no es numrico el dato.
MsgBox "El valor debe ser mayor que cero", vbCritical
txtH.SetFocus 'Situa el foco en el TexBox txtH.
End If
End Sub
El cdigo completo puede bajarse de AQU.
Este ejercicio es una nueva versin del juego de memoria que busca
dos imgenes iguales, para que vayan desapareciendo. Le hemos
hecho una presentacin y luego el juego en s. El cdigo es el
siguiente:
Picture3 = Picture4(a)
Picture3.Move Picture3.Left + 200, Picture3.Top - 100
If a >= 2 Then a = 0
If tiempo = 5 Then
Label5.Visible = True
ElseIf tiempo = 7 Then
Label6.Visible = True
ElseIf tiempo = 11 Then
Label1.Visible = True
ElseIf tiempo = 13 Then
Label2.Visible = True
ElseIf tiempo = 15 Then
Label3.Visible = True
ElseIf tiempo = 16 Then
Label4.Visible = True
End If
a=a+1
End Sub
Para el segundo formulario:
Option Explicit
Public Bandera As Long 'Para contar las veces que se hace click
'sobre las figuras.
Dim Figura(8) As String 'Para guardar las figuras concordantes.
Dim Chequear As String 'Para contar las figuras durante la
reconstruccin.
Dim ctlPrimeraFigura As Control 'Variables de control para la primera
Dim ctlSegundaFigura As Control 'y el segunda figura.
Dim UnoMostrado As Boolean 'Para llevar la cuenta de los
mostrados.
Dim AmbosMostrados As Boolean
Dim Pares As Integer 'Lleva la cuenta de los pares.
Dim Segundos As Long 'Para llevar el tiempo.
Dim Puntuacion As Integer 'Para llevar la puntuacin.
Dim Inicio As Date
Dim I As Integer
Sub FigurasVisibles()
'Hace todas las Figuras visibles
For I = 1 To 16
picFigura(I - 1).Visible = True
Next I
End Sub
Sub VoltearImagen()
'Voltea las imagenes cargando al Picture picVoltear.
For I = 1 To 16
picFigura(I - 1).Picture = picVoltear.Picture
Next I
End Sub
Sub HabilitarTodos()
'Habilita todas las Figuras.
For I = 1 To 16
picFigura(I - 1).Enabled = True
Next I
End Sub
Sub Verificar() 'Para ver si las dos figuras son iguales.
Dim I As Single
If ctlPrimeraFigura.Tag = ctlSegundaFigura.Tag Then 'Si las figuras
coinciden
Pares = Pares + 1
For I = 1 To 10000 'para mostrar las dos figuras un tiempo.
ctlPrimeraFigura.Visible = False
ctlSegundaFigura.Visible = False
Next
If Pares = 8 Then 'Si se termin el juego.
Timer2.Enabled = False 'Inhabilitar el reloj.
lblTiempo.Caption = CStr(Abs(Segundos))
If Segundos < Puntuacion Then
MsgBox "Tiempo empleado: " & Segundos & " segundos " & Chr(10)
& "Puntuacion : " & CStr(Bandera), vbInformation
mnuIniciar_Click
End If
End If
Else
AmbosMostrados = True
End If
End Sub
Sub ChequearFigura() 'Chequea si es la primera o segunda figura
que se volteado.
If UnoMostrado Then 'si una figura esta visible.
Set ctlSegundaFigura = Screen.ActiveControl 'Activa la variable
control.
Call Verificar
UnoMostrado = False
Else
Set ctlPrimeraFigura = Screen.ActiveControl 'Activa la variable
control.
ctlPrimeraFigura.Enabled = False
UnoMostrado = True
End If
End Sub
Function MezclarFiguras() As Integer 'Genera un nmero aleatorio
entre 0 y 7.
'para asignarlo a las figuras.
End Sub
El cdigo completo puede bajarse de AQU.