Vous êtes sur la page 1sur 2

PRACTICA N 3

1. BASES TERICAS:
a) CONTROLES: ComboBox (Cuadro Combinado): Este control es una combinacin del control TextBox (cuadro de texto) y un control ListBox (cuadro de lista). Este control permite que el usuario seleccione un elemento; para ello, escriba el texto en el cuadro de texto o seleccione un elemento en la lista. b) PROPIEDADES b.1 Selected: Devuelve o establece el estado de seleccin de un elemento de un control FileListBox o ListBox. Esta propiedad es una matriz de valores booleanos con el mismo nmero de elementos que la propiedad List. No est disponible en tiempo de diseo. Sintaxis: objeto.Selected(ndice) [= booleano] La sintaxis de la propiedad Selected consta de las siguientes partes: Parte Descripcin objeto Una expresin que especifica un objeto particular. ndice El nmero de ndice del elemento en el control. booleano Una expresin de tipo Boolean que especifica si el elemento est seleccionado, como se describe en Valores. Valores Los valores admitidos para booleano son: Valor True False Descripcin El elemento est seleccionado. (Predeterminado) El elemento no est seleccionado.

2. EJERCICIOS
2.1 Disee un formulario para el ingreso de registros de datos, deber implementar las operaciones de: grabar, eliminar, nuevo, modificar y salir. a) DISEO DEL FORMULARIO:

Visual Basic

30

b) CODIFICACIN: La codificacin para cada uno de los objetos es la siguiente:


General Declaraciones Dim x As Integer Private Sub Command1_Click() If x = 1 Then List1.AddItem Text1 List2.AddItem Text2 List3.AddItem Text3 List4.AddItem Text4 End If If x = 2 Then n = List1.ListIndex List1.List(n) = Text1 List2.List(n) = Text2 List3.List(n) = Text3 List4.List(n) = Text4 End If End Sub Private Sub Command2_Click() If List1.ListIndex = -1 Then MsgBox "No existe ningn elemento seleccionado" Else n = List1.ListIndex List1.RemoveItem (n) List2.RemoveItem (n) List3.RemoveItem (n) List4.RemoveItem (n) End If End Sub Private Sub Command3_Click() x=1 Text1 = "" Text2 = "" Text3 = "" Text4 = "" Text1.SetFocus End Sub Private Sub Command4_Click() x=2 If List1.ListIndex = -1 Then MsgBox "No existe ningn elemento seleccionado" Else n = List1.ListIndex Text1 = List1.List(n) Text2 = List2.List(n) Text3 = List3.List(n) Text4 = List4.List(n) Text1.SetFocus End If End Sub Private Sub Command5_Click() Unload Me End Sub Private Sub Form_Activate() x=1 End Sub Private Sub List1_Click() n = List1.ListIndex List2.Selected(n) = True List3.Selected(n) = True List4.Selected(n) = True End Sub Private Sub List2_Click() n = List2.ListIndex List1.Selected(n) = True List3.Selected(n) = True List4.Selected(n) = True End Sub Private Sub List3_Click() n = List3.ListIndex List1.Selected(n) = True List2.Selected(n) = True List4.Selected(n) = True End Sub Private Sub List4_Click() n = List4.ListIndex List1.Selected(n) = True List2.Selected(n) = True List3.Selected(n) = True End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.SetFocus End If End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text3.SetFocus End If End Sub Private Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text4.SetFocus End If End Sub Private Sub Text4_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Command1.SetFocus End If End Sub

c) EJECUCIN: Presione F5 Visual Basic 31

Vous aimerez peut-être aussi