Documentos de Académico
Documentos de Profesional
Documentos de Cultura
EJERCICIOS Y PRACTICAS
VISTUAL BASIC
01
INTRODUCCION
Bienvenido al curso de Visual Basic, este cuaderno de ejercicios y practicas complementa su Guia de
Estudio (apoyo teorico) para que realice los ejercicios correspondientes segn se los vaya presentando
su profesor.
Todos los ejercicios y practicas fueron realizadas con MS Visual Basic 6.0. Los ejercicios son expuestos
paso a paso y al final contienen algunas preguntas que deben ser contestadas. Las practicas por lo
general no contienen la solucion en este cuaderno para que el alumno las desarrolle por su cuenta.
02
mnuFile
mnuFileSalir
cmdSalir
txtCent
txtFahr
vsbTemp
lblCent
lblFahr
PROPIEDAD
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
text
Name
text
Name
Min
Max
SmallChange
LargeChange
Value
Name
Caption
Font
Name
Caption
Font
VALOR
frmTemp
Conversor de Temperaturas
mnuFile
&Archivo
mnuFileSalir
&Salida
cmdSalir
Salir
txtCent
0
txtFahr
32
vsbTemp
100
-100
1
10
0
lblCent
Grados Centigrados
MS Sans Serif, 10
lblFahr
Grados Fahrenheit
MS Sans Serif, 10
03
Option Explicit
Private Sub cmdSalir_Click()
Beep
End
End Sub
Private Sub mnuFileExit_Click()
End
End Sub
Private Sub vsbTemp_Change()
txtCent.text = vsbTemp.value
txtFahr.text = 32 + 1.8 * vsbTemp.value
End Sub
04
Responde a lo siguiente:
PREGUNTA
Que son los controles en Visual Basic?
Cules son los controles que usamos en este
programa?
Cmo ponemos nombre a nuestros controles?
Cmo ponemos un valor de texto a nuestros
controles?
Cul es la instruccin o comando que termina el
programa?
Dnde ponemos el codigo del programa?
RESPUESTA
Son los objetos visuales que representan elementos y
tienen propiedades, eventos y metodos
El ScrollBar Vertiical, la caja de texto, la etiqueta y el
boton de comando
Con la propiedad NAME
Con la propiedad Caption, Text o Value
END
fraColores
optAzul
optRojo
optAmarillo
optVerde
fraPosicion
optArriba
optAbajo
PROPIEDAD
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
VALOR
frmColores0
Colores
fraColor
Colores
optAzul
Azul
optRojo
Rojo
optAmarillo
Amarillo
optVerde
Verde
fraPosicion
Posicion
optArriba
Arriba
optAbajo
Abajo
05
txtCaja
Name
Text
txtCaja
Y el codigo es:
Option Explicit
Private Sub Form_Load()
txtCaja.Top = 0
End Sub
06
Responde a lo siguiente:
PREGUNTA
Cules son las propiedades de la caja de texto que
estamos usando en este programa?
Qu otros controles estamos viendo en este
ejercicio?
Cmo cambiamos el color de fondo de control de
textbox?
RESPUESTA
Top y BackColor
Frame y Option
Con la propiedad BackColor
07
Ejercicio 3 MiniCalculadora
En este ejemplo se muestra una calculadora elemental que permite hacer las cuatro operaciones
aritmeticas. Los archivos de este proyecto se pueden llamar minicalc.vbp y minicalc.frm
CONTROL
Form
textbox
textbox
textbox
label
label
CommandButton
CommandButton
CommandButton
CommandButton
PROPIEDAD
Name
Caption
Name
Text
Name
Text
Name
Text
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
VALOR
frmMinicalc
Minicalculadora
txtOper1
txtOper2
txtResult
lblOp
lblEqual
=
cmdSuma
+
cmdResta
cmdMulti
*
cmdDiv
/
08
Responde a lo siguiente:
PREGUNTA
Para que usamos la funcion VAL() de VisualBasic?
RESPUESTA
Para convertir las letras de las cajas de texto en
numeros y poder realizar las opereaciones
Suma, resta, multiplicacion y division
En cada uno de los botones de comandos, en el
evento CLICK()
09
Ejercicio 1
10
11
12
13
14
15
suplemento.Caption = precio
res = Val(suplemento.Caption) + Val(Total.Caption)
PVP.Caption = res
End Sub
Private Sub Form_Load()
Total.Alignment = 1
suplemento.Alignment = 1
PVP.Alignment = 1
suplemento.Caption = "0"
End Sub
Private Sub kit_Click()
Dim precio As Long
Dim res As Long
precio = 0
res = 0
If kit.Value = 1 Then
precio = Val(suplemento.Caption) + 35000
Else
precio = Val(suplemento.Caption) = -35000
End If
suplemento.Caption = precio
res = Val(suplemento.Caption) + Val(Total.Caption)
PVP.Caption = res
End Sub
Private Sub pantalla_Click()
Dim precio As Long
Dim res As Long
precio = 0
res = 0
If pantalla.Value = 1 Then
precio = Val(suplemento.Caption) + 120000
Else
precio = Val(suplemento.Caption) = -120000
End If
suplemento.Caption = precio
res = Val(suplemento.Caption) + Val(Total.Caption)
PVP.Caption = res
End Sub
Private Sub Ram_Click()
Dim precio As Long
Dim res As Long
precio = 0
res = 0
If Ram.Value = 1 Then
precio = Val(suplemento.Caption) + 80000
16
Else
precio = Val(suplemento.Caption) = -80000
End If
suplemento.Caption = precio
res = Val(suplemento.Caption) + Val(Total.Caption)
PVP.Caption = res
End Sub
Ejercicio 7
17
Unload txtRef(n)
Unload txtDes(n)
Unload txtCan(n)
Unload txtPre(n)
n=n-1
End Sub
18
Printer.CurrentY = Controls(i).Top
Return
End Sub
Private Sub btnNueva_Click()
n=1
If n > 4 Then
MsgBox "Albarn completo", 16, "Error"
n=4
Exit Sub
End If
'Referencia
Load txtRef(n)
txtRef(n).Top = txtRef(n - 1).Top + 350
txtRef(n).Visible = True
txtRef(n).Text = ""
'Descripcin
Load txtDes(n)
txtDes(n).Top = txtDes(n - 1).Top + 350
txtDes(n).Visible = True
txtDes(n).Text = ""
'Precio
Load txtPre(n)
txtPre(n).Top = txtPre(n - 1).Top + 350
txtPre(n).Visible = True
txtPre(n).Text = ""
'Cantidad
Load txtCan(n)
txtCan(n).Top = txtCan(n - 1).Top + 350
txtCan(n).Visible = True
txtCan(n).Text = ""
End Sub
Private Sub Form_Load()
n=0
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim Msg
Msg = "Desea salir de la aplicacin?"
If MsgBox(Msg, 36, Me.Caption) = 7 Then
Cancel = True
End If
End Sub
19