Arrays+and+Lists+(VB)

Public Class Form1 Dim lstGroceries As New List(Of String) Dim strGroceries(5) As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddList.Click lstGroceries.Add(txtAddList.Text) lbxList.Items.Add(txtAddList.Text) End Sub Private Sub cmdShowList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShowList.Click lstGroceries.Add("Eggs") lstGroceries.Add("Bread") lstGroceries.Add("Quinoa") lstGroceries.Add("YOP") lstGroceries.Add("Bowtie Pasta") lstGroceries.Add("Lobster bisque")
 * ADD TO LIST**
 * ADD EACH TO LIST**

For Each item In lstGroceries lbxList.Items.Add(item) Next
 * ADDING EACH ITEM IN LIST TO THE LISTBOX**

For Each item In lstGroceries cbxRemoveList.Items.Add(item) Next
 * REMOVE EACH ITEM FROM LIST THAT IS ADDED TO THE LISTBOX.**

End Sub

Private Sub cmdShowArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShowArray.Click strGroceries(0) = "Eggs" strGroceries(1) = "Bread" strGroceries(2) = "Quinoa" strGroceries(3) = "YOP" strGroceries(4) = "Bowtie Pasta" strGroceries(5) = "Lobster bisque"
 * ADDING EACH ITEM TO THE ARRAY.**

For x = 0 To strGroceries.Length - 1 lbxArray.Items.Add(strGroceries(x)) cbxRemoveArray.Items.Add(strGroceries(x)) Next
 * FOR EVERY ITEM IN THE ARRAY......ADD TO THE LIST BOX AND REMOVE FROM THE ARRAY.**

End Sub

Private Sub cmdHideList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHideList.Click lbxList.Items.Clear End Sub

Private Sub cmdHideArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHideArray.Click lbxArray.Items.Clear End Sub

Private Sub cmdAddArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddArray.Click ReDim strGroceries(strGroceries.Length) strGroceries(strGroceries.Length - 1) = txtAddArray.Text lbxArray.Items.Add(txtAddArray.Text) End Sub
 * ADD AN ITEM TO THE ARRAY IN RUNTIME (REDIM OR REDECLARE!!!)**

Private Sub cmdRemoveList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemoveList.Click lstGroceries.Remove(cbxRemoveList.SelectedItem) lbxList.Items.Clear For Each item In lstGroceries lbxList.Items.Add(item) Next
 * REMOVE AN ITEM FROM THE LIST THAT IS SELECTED!!**

cbxRemoveList.Items.Remove(cbxRemoveList.SelectedItem)

End Sub

Private Sub cmdRemoveArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemoveArray.Click strGroceries.(cbxRemoveArray.SelectedItem) lbxArray.Items.Clear End Sub End Class