domingo, 20 de julio de 2014

ListBox

Fecha: Julio-21-2014
Asignatura: Tecnología e Informática.
Formación en Valor: Autonomía.

Núcleo Integrador: ListBox.
Objetivo: Programar listas.


ListBox:  Este objeto nos permite mostrar una lista de opciones 


Ejercicio Diseña el siguiente formulario:


Copia el siguiente código y muestra el resultado con F5.

Dim x As Integer
Private Sub Command1_Click()
 If List1.ListIndex = -1 Then
   MsgBox "Seleccione el elemento", vbInformation, "ListBox"
 Else
   List2.AddItem List1.Text
   List1.RemoveItem List1.ListIndex
 End If
End Sub

Private Sub Command2_Click()
 If List1.ListIndex = -1 Then
   MsgBox "Seleccione el elemento", vbInformation, "ListBox"
 Else
   For x = 0 To List1.ListCount
     List2.AddItem List1.List(x)
   Next x
   List1.Clear
 End If
End Sub

Private Sub Command3_Click()
If List2.ListIndex = -1 Then
   MsgBox "Seleccione el elemento", vbInformation, "ListBox"
 Else
   List1.AddItem List2.Text
   List2.RemoveItem List2.ListIndex
 End If
End Sub

Private Sub Command4_Click()
 If List2.ListIndex = -1 Then
   MsgBox "Seleccione el elemento", vbInformation, "ListBox"
 Else
   For x = 0 To List2.ListCount
     List1.AddItem List2.List(x)
   Next x
   List2.Clear
 End If
End Sub

Private Sub Form_Load()
  List1.AddItem "ELEMENTO 1"
  List1.AddItem "ELEMENTO 2"
  List1.AddItem "ELEMENTO 3"
  List1.AddItem "ELEMENTO 4"
End Sub


Taller: 
Teniendo en cuenta el ejercicio anterior, desarrolle un programa que permita realizar una venta de diferentes artículos.

Nota: analice como utilizaría usted el siguiente código para incorporarlo en su nuevo programa.

Private Sub List1_Click()
  Select Case List1.ListIndex
    Case 0
      Label1 = 100
    Case 1
      Label1 = 200
    Case 2
      Label1 = 150
    Case 3
      Label1 = 500
  End Select
End Sub

No hay comentarios:

Publicar un comentario