
Information Retrieval in Lab Settings
Learn about arrays in programming, how to declare, initialize, retrieve values, and perform operations like resizing and sorting. Explore the concept of Lists and how to add items to them efficiently.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
First Lab Information Retrieval By Zinah Sadeq
Array Arrays are using for store similar data types grouping as a single unit. It is a fixed collection of same data type that are stored contiguously and that are accessible by an index Declaring and Initializing an Array Dim num(3) As Integer num(0) = 10 num(1) = 20 num(2) = 30 num(3) = 40 Dim num() As Integer = New Integer(3) {} num(0) = 10 num(1) = 20 num(2) = 30 num(3) = 40
Dim num() As Integer = New Integer(3) {10, 20, 30, 40} Dim num(3) As Integer For i As Integer = 0 To num.Length - 1 num(i) = InputBox("Enter the elements", "input box", "enter here", 75, 75) Next retrieve these values from array by using : For loop For i As Integer = 0 To num.Length - 1 ListBox1.Items.Add(num(i)) Next
For Each loop For Each number As Integer In num ListBox1.Items.Add(number) Next Resize an Array Array.Resize(num, 3) For i As Integer = 0 To num.Length - 1 ListBox2.Items.Add(num(i)) Next Array Sort in ascending order Array.Sort(num) Array Sort in descending order Array.Reverse(num)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim num(3) As Integer num(0) = 55 num(1) = 7 num(2) = 10 num(3) = 1 'display the element of list using for each For Each number As Integer In num ListBox1.Items.Add(number) Next 'display the element of list using for statement For i As Integer = 0 To num.Length - 1 ListBox2.Items.Add(num(i)) Next
'Sort elements of array in ascending order Array.Sort(num) For i As Integer = 0 To num.Length - 1 ListBox3.Items.Add(num(i)) Next 'Sort elements of array in descending order Array.Reverse(num) For i As Integer = 0 To num.Length - 1 ListBox4.Items.Add(num(i)) Next 'resize the array size Array.Resize(num, 2) For i As Integer = 0 To num.Length - 1 ListBox5.Items.Add(num(i)) Next End Sub
List is a generic implementation of ArrayList. List can store only one type of objects, that type supplied as its generic parameter. List(Of T) The parameter T is the type of elements in the list. How to add items in List ? Add integer values in the List Dim iList As New List(Of Integer)() iList.Add(2) iList.Add(3) iList.Add(5) iList.Add(7) How to count number of items exists in a List ? List.Count property gives you the number of items exists in List iList.Count
How to retrieve items from List ? You can retrieve items from List collection by using for loops. foreach loop For Each number As Integer In iList MessageBox.Show(number) Next for loop For i As Integer = 0 To iList.Count - 1 MessageBox.Show(iList(i)) Next How to insert an item in the List ? You can use insert(index,item) method to insert an in the specified index. iList.Insert(1, 100) In the above code the number 100 is inserted in the index position 1.
How to remove an item from List collection? List.Remove() can use to remove item from List. iList.Remove(3) How to check if an item exist in the List ? You can use List.Contains() method to check an item exists in the List. If (iList.Contains(7)) Then MessageBox.Show(" exist in the list"); End If Finally clear method remove all the items from List collection. iList.Clear()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim iList As New List(Of Integer)() iList.Add(2) iList.Add(3) iList.Add(5) iList.Add(7) 'display the element of list using for each For Each number As Integer In iList ListBox1.Items.Add(number) Next For i As Integer = 0 To iList.Count - 1 ListBox2.Items.Add(iList(i)) Next 'Insert an item to list iList.Insert(1, 35) For i As Integer = 0 To iList.Count - 1 ListBox3.Items.Add(iList(i)) Next
'Remove element from list iList.Remove(7) For i As Integer = 0 To iList.Count - 1 ListBox4.Items.Add(iList(i)) Next 'to check if the list contain specific value If iList.Contains(35) Then MessageBox.Show("exist in the list") End If 'call clear method iList.Clear() For i As Integer = 0 To iList.Count - 1 ListBox5.Items.Add(iList(i)) Next End Sub End Class