domingo, 4 de agosto de 2013

ListBox

Fecha: Agosto-5-2013
Asignatura: Tecnología e Informática.
Formación en Valor: Caridad
Núcleo Integrador: ListBox.
Objetivo: Utilizar listas de opciones en un programa.


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.
Utilice el mismo código pero cambie los nombres de los artículos a vender (List1) y cuando de clic sobre la lista debe agregar este código

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


Al agregar un elemento adicione este código:
Label2 = Val(Label2) + Val(Label1)

NOTA: Note que debe adicionar dos Label (Label1 y Label2)


No hay comentarios:

Publicar un comentario