El documento describe los pasos para crear una aplicación móvil de agenda en Visual Basic .NET, incluyendo la creación de módulos, formularios y funcionalidad. Se crea un módulo para almacenar variables y un array. Se agregan controles a los formularios principal y de detalle, y se establecen propiedades. Finalmente, se agrega código para permitir funciones como nuevo contacto, edición, eliminación y búsqueda.
1. I.S.T. “F.P.G.V.”
Computación e Informática Taller de Aplicaciones Móviles
GUÍA DE LABORATORIO N° 01
OBJETIVOS:
Desarrollo de Aplicaciones Móviles con .NET Compact Framework de .NET 2005.
Uso de Arrays.
Creación de variables de memoria con diferentes ámbitos.
Uso de procedimientos creados por el usuario.
Manejo de estructuras de control y repetitivas.
1.1 INGRESAR A MICROSOFT VISUAL BASIC .NET:
Debe hacer clic en el botón Inicio, luego en Programas, luego Microsoft Visual Studio 2005, luego
Microsoft Visual Studio 2005, luego al ingresar nos visualizará la siguiente ventana:
1.2 CREACIÓN DEL PRIMER PROYECTO
Un proyecto es la aplicación desarrollada en un entorno de programación, en éste caso Visual Basic, y está
compuesto por varios elementos
como son Formularios, Clases,
Módulos, etc.
Para crear un Proyecto es necesario
ir al Menú Archivo, luego hacer clic
en Nuevo Proyecto ó pulse las
telas CTRL + N, a continuación nos
mostrará la siguiente ventana:
Considere lo siguiente:
1. Tipo de Proyecto: - Visual
Basic.
- Smart Device
- Pocket PC 2003
2. Plantilla: Aplicación de
Dispositvo
3. Luego escriba el nombre del
proyecto: AGENDA
4. Por último haga clic Aceptar para crear el proyecto.
Docente: José Luis Ponce Segura Prac01 (1 de 8) e-mail: jlponcesg@hotmail.com
Cel. : 952636911 www.redtacna.net
2. I.S.T. “F.P.G.V.”
Computación e Informática Taller de Aplicaciones Móviles
1.3 IDE - ENTORNO DE DESARROLLO INTEGRADO DE VISUAL STUDIO 2005
Cuando se crea un nuevo proyecto para una aplicación móvil, se muestra una pantalla que tiene varios
elementos que nos servirán para generar y configurar nuestra aplicación.
Formulario para el
Cuadro de Herramientas Dispositivo móvil Explorador de Soluciones
Ventana de Propiedades
Ventana de Código – (accede presionando F7)
Docente: José Luis Ponce Segura Prac01 (2 de 8) e-mail: jlponcesg@hotmail.com
Cel. : 952636911 www.redtacna.net
3. I.S.T. “F.P.G.V.”
Computación e Informática Taller de Aplicaciones Móviles
1.4 CREACIÓN DEL MÓDULO:
MODULO: Es un modulo de clase donde se declaran variables y/o procedimientos a nivel de toda la
solución y/o proyectos de Visual Basic .NET.
Cómo se agrega un módulo al proyecto
Haga clic en el menú PROYECTO
Luego seleccione con un clic en la opción AGREGAR NUEVO ELEMENTO
Se presenta una ventana de dialogo seleccione MODULO y escriba el nombre: MODGENERAL luego clic
en el botón AGREGAR.
Seguidamente se presentará una ventana en blanco para la codificación del modulo correspondiente.
ESCRIBA EL SIGUIENTE CÓDIGO EN EL MODULO:
Public agenda(99, 7) As String ‘ Array
Public contacto As String
Public n, ncodi, detalle As Byte
1.5 CREACIÓN DE LOS FORMULARIOS PARA LA AGENDA
1.5.1 FORMULARIO (FRMAGENDA.VB)
INTERFAZ GRÁFICA DEL USUARIO: AGREGAR
CONTROLES AL FORMULARIO
Seleccione el formulario Form1 y realice lo siguiente:
En el formulario insertar los siguientes controles
desde el cuadro de Herramientas de Windows Forms:
01 ListBox
01 PictureBox
01 TextBox
01 MainMenu (Es agregado por defecto)
INTERFAZ GRÁFICA DEL USUARIO: ESTABLECER
PROPIEDADES A LOS OBJETOS
Proceda e establecer una imagen al picturebox1 y
establezca la propiedad SizeMode = StretchImage
Luego deberá crear el menú de opciones con las
propiedades NAME y TEXT según la siguiente tabla:
Menú de Opciones Propiedad Valor Asignado
Name MenuNuevoCto
Text Nuevo Contacto
Name MenuEditarCto
Text Editar Contacto
Name MenuDetalleCto
Text Detalle de Contacto
Docente: José Luis Ponce Segura Prac01 (3 de 8) e-mail: jlponcesg@hotmail.com
Cel. : 952636911 www.redtacna.net
4. I.S.T. “F.P.G.V.”
Computación e Informática Taller de Aplicaciones Móviles
ESCRIBIR CÓDIGO PARA AÑADIR FUNCIONALIDAD
Private Sub NuevoEditaDetalle(ByVal sw As Byte, ByVal x1 As Byte)
Dim frm As New frmDetalleAgenda
Dim numero As Byte
If sw > 1 Then numero = ListBox1.SelectedIndex
frm.operacion(x1, numero)
If frm.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
Select Case sw
Case 1 ' Nuevo
If contacto <> Nothing Then
ListBox1.Items.Add(contacto)
End If
Case 2 ' Edita
ListBox1.Items.Item(numero) = contacto
Case 3 ' Detalle
If detalle = 1 Then ' Edita
If contacto = Nothing Then Exit Sub
ListBox1.Items.Item(frm.posicion) = contacto
ElseIf detalle = 2 Then ' Elimina
Dim x As Byte
For x = 0 To ListBox1.Items.Count - 1
If contacto = ListBox1.Items.Item(x) Then
ListBox1.Items.RemoveAt(x)
Exit Sub
End If
Next
ElseIf detalle = 3 Then ' Cancela
' Puede Usted colocar código, luego que cancela una operación
End If
End Select
End If
End Sub
Private Sub veropciones(ByVal sw As Boolean)
MenuEditarCto.Enabled = sw
MenuDetalleCto.Enabled = sw
End Sub
Private Sub FrmAgenda1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
veropciones(False)
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.SelectedIndex = -1 Then
Exit Sub
End If
veropciones(True)
End Sub
Private Sub MenuNuevoCto_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuNuevoCto.Click
NuevoEditaDetalle(1, 1)
End Sub
Private Sub MenuEditarCto_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuEditarCto.Click
If ListBox1.SelectedIndex < 0 Then Exit Sub
NuevoEditaDetalle(2, 2)
MenuEditarCto.Enabled = False
End Sub
Docente: José Luis Ponce Segura Prac01 (4 de 8) e-mail: jlponcesg@hotmail.com
Cel. : 952636911 www.redtacna.net
5. I.S.T. “F.P.G.V.”
Computación e Informática Taller de Aplicaciones Móviles
Private Sub MenuDetalleCto_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuDetalleCto.Click
If ListBox1.SelectedIndex < 0 Then Exit Sub
NuevoEditaDetalle(3, 3)
MenuDetalleCto.Enabled = False
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Handles TextBox1.TextChanged
If ListBox1.Items.Count < 3 Then Exit Sub
Dim cadena As String = TextBox1.Text
Dim valorlista As String, x, num As Byte
num = cadena.Length
For x = 0 To ListBox1.Items.Count - 1
valorlista = Microsoft.VisualBasic.Left(ListBox1.Items.Item(x), num)
If cadena = valorlista Then
ListBox1.SelectedIndex = x
End If
Next
End Sub
1.5.2 FORMULARIO (FRMDETALLEAGENDA.VB)
INTERFAZ GRÁFICA DEL USUARIO: AGREGAR
CONTROLES AL FORMULARIO
Seleccione el formulario Form1 y realice lo siguiente:
En el formulario insertar los siguientes controles desde el
cuadro de Herramientas de Windows Forms:
07 TextBox
02 PictureBox
01 DomainUpDown
08 Label
01 MainMenu (Es agregado por defecto)
INTERFAZ GRÁFICA DEL USUARIO: ESTABLECER
PROPIEDADES A LOS OBJETOS
Establezca la propiedad NAME a los TextBox según se
aprecia en la imagen.
Proceda e establecer una imagen a los picturebox según
se aprecia en la imagen.
Establezca la propiedad Text a los LABEL según se
aprecia en la imagen.
Luego deberá crear el menú de opciones con las
propiedades NAME y TEXT según la siguiente tabla:
Menú de Opciones Propiedad Valor Asignado
Name MenuCancelar
Text Cancelar
Name MenuGuardar
Text Guardar
Name MenuEditar
Text Editar
Name MenuEliminar
Text Eliminar
Name MenuRegresar
Text Regresar
Docente: José Luis Ponce Segura Prac01 (5 de 8) e-mail: jlponcesg@hotmail.com
Cel. : 952636911 www.redtacna.net
6. I.S.T. “F.P.G.V.”
Computación e Informática Taller de Aplicaciones Móviles
ESCRIBIR CÓDIGO PARA AÑADIR FUNCIONALIDAD
‘ Sección Declaraciones
Dim guarda As Byte
Friend posicion As Byte
Private Sub frmDetalleAgenda_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
DomainUpDown1.Items.Add("Amigos")
DomainUpDown1.Items.Add("Familia")
DomainUpDown1.Items.Add("Trabajo")
DomainUpDown1.SelectedIndex = 0
contacto = ""
End Sub
Friend Sub operacion(ByVal op As Byte, Optional ByVal fila As Byte = 0)
Select Case op
Case 1 ' Para Nuevo
Dim codi As String = Format(ncodi + 1, "000")
veropciones(True)
' Debe llamar a un procedimiento para limpiar cajas de texto
txtCodigo.Text = codi
txtApellidos.Focus()
guarda = 1
posicion = n
Exit Sub
Case 2 ' Para Editar
veropciones(True)
leercajas(True)
guarda = 2
posicion = fila
Case 3 ' Para Detalle
veropciones(False)
leercajas(False)
posicion = fila
End Select
cargardatos(posicion)
End Sub
Private Sub cargardatos(ByVal nfil As Byte)
txtCodigo.Text = agenda(posicion, 0)
txtApellidos.Text = agenda(posicion, 1)
txtNombres.Text = agenda(posicion, 2)
txtTelefono1.Text = agenda(posicion, 3)
txtTelefono2.Text = agenda(posicion, 4)
txtemail.Text = agenda(posicion, 5)
txtweb.Text = agenda(posicion, 6)
DomainUpDown1.Text = agenda(posicion, 7)
End Sub
Friend Sub leercajas(ByVal sw As Boolean)
txtCodigo.ReadOnly = Not sw
txtApellidos.ReadOnly = Not sw
txtNombres.ReadOnly = Not sw
txtTelefono1.ReadOnly = Not sw
txtTelefono2.ReadOnly = Not sw
txtemail.ReadOnly = Not sw
txtweb.ReadOnly = Not sw
DomainUpDown1.ReadOnly = Not sw
End Sub
Docente: José Luis Ponce Segura Prac01 (6 de 8) e-mail: jlponcesg@hotmail.com
Cel. : 952636911 www.redtacna.net
7. I.S.T. “F.P.G.V.”
Computación e Informática Taller de Aplicaciones Móviles
Private Sub MenuGuardar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuGuardar.Click
If txtCodigo.Text = Nothing Or txtApellidos.Text = Nothing _
Or txtNombres.Text = Nothing Then
' Debe indicar los datos "cajas" obligatorios
MessageBox.Show("falta ingresar datos...", MessageBoxIcon.Exclamation)
Exit Sub
End If
Select Case guarda
Case 1 ' Para Guardar un nuevo contacto
n += 1 ' Incremento del num de elementos guardados en el array
ncodi += 1
Case 2 ' Para Guardar el contacto en edición
' Se está editando el contacto
End Select
contacto = txtApellidos.Text & " " & txtNombres.Text
agenda(posicion, 0) = txtCodigo.Text
agenda(posicion, 1) = txtApellidos.Text
agenda(posicion, 2) = txtNombres.Text
agenda(posicion, 3) = txtTelefono1.Text
agenda(posicion, 4) = txtTelefono2.Text
agenda(posicion, 5) = txtemail.Text
agenda(posicion, 6) = txtweb.Text
agenda(posicion, 7) = DomainUpDown1.Items.Item(DomainUpDown1.SelectedIndex)
Me.Close()
End Sub
Private Sub MenuCancelarRegresar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuCancelar.Click, MenuRegresar.Click
detalle = 3
Me.Close()
End Sub
Private Sub MenuEditar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuEditar.Click
detalle = 1
operacion(2, posicion)
End Sub
Private Sub MenuEliminar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuEliminar.Click
detalle = 2
contacto = txtApellidos.Text & " " & txtNombres.Text
' "ELiminar" elemento del Array
Dim x As Integer
For x = posicion To n - 1
If posicion = n - 1 Then
Exit For
Else
agenda(x, 0) = agenda(x + 1, 0)
agenda(x, 1) = agenda(x + 1, 1)
agenda(x, 2) = agenda(x + 1, 2)
agenda(x, 3) = agenda(x + 1, 3)
agenda(x, 4) = agenda(x + 1, 4)
agenda(x, 5) = agenda(x + 1, 5)
agenda(x, 6) = agenda(x + 1, 6)
agenda(x, 7) = agenda(x + 1, 7)
End If
Next
n -= 1
Me.Close()
End Sub
Docente: José Luis Ponce Segura Prac01 (7 de 8) e-mail: jlponcesg@hotmail.com
Cel. : 952636911 www.redtacna.net
8. I.S.T. “F.P.G.V.”
Computación e Informática Taller de Aplicaciones Móviles
Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles PictureBox1.Click
If posicion > 0 Then
posicion -= 1
cargardatos(posicion)
End If
End Sub
Private Sub PictureBox2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles PictureBox2.Click
If posicion < (n - 1) Then
posicion += 1
cargardatos(posicion)
End If
End Sub
Friend Sub veropciones(ByVal sw As Boolean)
Me.MenuCancelar.Enabled = sw
Me.MenuGuardar.Enabled = sw
Me.MenuEditar.Enabled = Not sw
Me.MenuEliminar.Enabled = Not sw
Me.MenuRegresar.Enabled = Not sw
End Sub
PROBAR Y DEPURAR LA APLICACIÓN
Seguidamente ejecute la aplicación, para ello pulse la tecla F5 ó haga clic en el botón
de la barra
de herramientas
Si ocurre algún error revise el código y/o corríjalo “depurar”.
Ahora proceda a guardar el proyecto, para ello haga clic en el botón Guardar todo de la Barra de
Herramientas.
Botón Guardar Botón Guardar todo
Nombre del Proyecto: AGENDAMOVIL
1.6 AHORA HÁGALO USTED
Mejore Usted la aplicación de la presente práctica, deberá validar los datos de entrada, aspecto, etc.
Así también agregue aplicaciones cómo Alarma, Calendario de Eventos, Calculadora, etc.
Docente: José Luis Ponce Segura Prac01 (8 de 8) e-mail: jlponcesg@hotmail.com
Cel. : 952636911 www.redtacna.net