1 Chapter 7 – Arrays 7.1 Creating and Accessing Arrays 7.2 Using LINQ with Arrays 7.3 Arrays of Structures 7.4 Two-Dimensional Arrays 7.5 A Case Study:

Slides:



Advertisements
Similar presentations
Arrays. What is an Array? An array is a way to structure multiple pieces of data of the same type and have them readily available for multiple operations.
Advertisements

Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
Introduction to Arrays Chapter 7 Why use arrays? To store & represent lists of homogeneous values To simplify program code To eliminate the need to reread.
Arrays.
Chapter 71 Array Properties Upper Bound: The value of arrayName.GetUpperBound(0) is the upper bound of arrayName(). Then What is the Lower Bound ? Ans:
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
Chapter 8 - VB.Net by Schneider1 Chapter 8 – Sequential Files 8.1 Sequential Files Creating a Sequential File Adding Items to a Sequential File Error Trapping.
Chapter 10 - VB.Net by Schneider1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Relational Databases and SQL.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
1 Microsoft Visual Basic 2010 Arrays. 2 Using a One-Dimensional Array Lesson A Objectives After completing this lesson, you will be able to:  Declare.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Using Arrays and File Handling
1 Chapter 8 – Text Files 8.1 Managing Text Files 8.2 StreamReaders, StreamWriters, and Structured Exception Handling 8.3 XML.
1 Text Files Managing Text Files StreamReaders, StreamWriters, ReadAllLines, and WriteAllLines Method The OpenFileDialog Control Structured Exception Handling.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Thirteen Working with Access Databases and LINQ.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
1 Chapter 7 – Arrays 7.1 Creating and Accessing Arrays 7.2 Using LINQ with Arrays 7.3 Arrays of Structures 7.4 Two-Dimensional Arrays 7.5 A Case Study:
1 Chapter 7 – Arrays 7.1 Creating and Using Arrays 7.4 Two-Dimensional Arrays.
Chapter 7 – Arrays 7.1 Creating and Accessing Arrays
Chapter Six: Working With Arrays in Visual Basic.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
Chapter 7 - VB 2008 by Schneider1 Chapter 7 – Arrays 7.1 Creating and Accessing Arrays 7.2 Using Arrays 7.3 Some Additional Types of Arrays 7.4 Sorting.
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Chapter 71 Arrays Creating and Accessing Arrays Using Arrays Some Additional Types of Arrays.
1 Chapter 7 – Arrays 7.1 Creating and Accessing Arrays 7.2 Using LINQ with Arrays 7.3 Arrays of Structures 7.4 Two-Dimensional Arrays 7.5 A Case Study:
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
Tutorial 101 Variable Arrays A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved. - Edited By: Maysoon Al-Duwais 1.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
Chapter 7 - VB.Net by Schneider1 Chapter 7 – Arrays 7.1 Creating and Accessing Arrays 7.2 Using Arrays 7.3 Control Arrays Skip Structures (7.3), 7.4 and.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine.
Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Binding to ListBox and ComboBox Controls List and combo boxes are frequently.
Introduction to programming in java Lecture 21 Arrays – Part 1.
1 Chapter 7 – Arrays 7.1 Creating and Using Arrays 7.2 Using LINQ with Arrays 7.3 Arrays of Structures 7.4 Two-Dimensional Arrays.
INF230 Basics in C# Programming
Microsoft Visual Basic 2010: Reloaded Fourth Edition
IS 350 Arrays.
Chapter 7 Arrays.
ARRAYS.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
Visual Basic 2010 How to Program
Chapter 7 – Arrays 7.1 Creating and Accessing Arrays
CIS16 Application Development and Programming using Visual Basic.net
© 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Introduction to Computer Programming IT-104
Presentation transcript:

1 Chapter 7 – Arrays 7.1 Creating and Accessing Arrays 7.2 Using LINQ with Arrays 7.3 Arrays of Structures 7.4 Two-Dimensional Arrays 7.5 A Case Study: Analyze a Loan

2 Using Arrays Dim students(29) As String Dim scores(29) As Double Array name Upper bound of subscripts in the array Data type

3 Initializing Arrays Arrays may be initialized when created: Dim arrayName() As DataType = {value0, value1, value2,..., valueN} declares an array having upper bound N and assigns value0 to arrayName(0), value1 to arrayName(1),..., and valueN to arrayName(N). Example: Dim teamNames() As String = {"Packers", "Packers", "Jets", "Chiefs"}

4 Split Example For instance, suppose the string array employees has been declared without an upper bound, and the string variable line has the value “Bob,23.50,45”. employees = line.Split(","c) sets the size of employees to 3 sets employees(0) = “Bob” sets employees(1) = “23.50” sets employees(2) = “45”

5 Example Private Sub btnConvert_Click(...) _ Handles btnConvert.Click Dim stateData(), line As String line = "California,1850,Sacramento,Eureka" stateData = line.Split(","c) For Each entry As String In stateData lstOutput.Items.Add(entry) Next End Sub

6 Example Output California 1850 Sacramento Eureka

7 7.2 Using LINQ with Arrays LINQ Queries The Distinct Operator The ToArray Method Use of Function Procedures in Queries The Let Operator The OrderBy Operator The DataSource Property Binary Search

What is LINQ? LINQ stands for Language INtegrated Query A query is a request for information. Note: Option Infer must be set to ON in order to use LINQ 8

LINQ Query Code of the form range variable Dim queryName = From var In arrayName source data Where [condition on var] Select var declares the variable queryName and assigns to it a sequence of the values from arrayName that satisfy the stated condition. 9 query operators

LINQ Query (continued) The values in the sequence can be converted to an array, displayed in a list box, or written to a text file. 10

Example 1 'States.txt contains names of the 50 states Dim states() As String = IO.File.ReadAllLines("States.txt") Dim stateQuery = From state In states Where state.Length = 5 Select state For Each state As String In stateQuery lstStates.Items.Add(state) Next Output: Maine, Texas, Idaho 11

Example 2 Dim nums() As Integer = {5, 12, 8, 7, 11} Dim numQuery = From num In nums Where num > 7 Select num For Each num As Integer In numQuery lstBox.Items.Add(num) Next Output: 12, 8, 11 12

Distinct Operator Dim nums() As Integer = {5, 12, 5, 7, 12} Dim numQuery = From num In nums Select num Distinct For Each num As Integer In numQuery lstBox.Items.Add(num) Next Output : 5, 12, 7 13

ToArray Method A query variable is not an array variable. The ToArray method converts it to an array variable. Dim nums() As Integer = {5, 12, 5, 7, 12} Dim numQuery = From num In nums Select num Dim numArray() As Integer = numQuery.ToArray 14

Function Procedures in Queries Function procedures are commonly used in Where and Select clauses Dim presQuery = From pres In presidents Where FirstName(pres) = txtFirstName.Text Select IncludeTitle(pres) For Each pres In presQuery lstPres.Items.Add(pres) Next 15

Order By Operator Sorts string values into alphabetical order (either ascending or descending) Sorts numbers into numeric order (either ascending or descending) 16

Example of Let Operator Dim presQuery = From pres In presidents Select IncludeTitle(pres) can be replaced with Dim presQuery = From pres In presidents Let formalName = Includetitle(pres) Select formalName 17

Example 4 Dim nums() As Integer = {3, 6, 4, 1} Dim numQuery = From num In nums Order By num Ascending Select num For Each n As Integer In numQuery lstOutput.Items.Add(n) Next Output: 1, 3, 4, 6 18

Example 5 Dim states() As String = IO.File.ReadAllLines("States.txt") Dim stateQuery = From state In states Order By state.Length Ascending, state Descending Select state For Each state As String In stateQuery lstStates.Items.Add(state) Next Output : Utah, Ohio, Iowa, Texas, Maine,... 19

DataSource Property The DataSource property fills a list box with the values returned by a query. lstBox.DataSource = queryName.ToList The first entry will be highlighed. The highlighting can be eliminated with lstBox.SelectedItem = Nothing 20

Alternative for Example 5 Dim states() As String = IO.File.ReadAllLines("States.txt") Dim stateQuery = From state In states Order By state.Length Ascending, state Descending Select state lstStates.DataSource = stateQuery.ToList lstStates.SelectedItem = Nothing optional line Output: Utah, Ohio, Iowa, Texas, Maine,... 21

DataGridView Control Useful when two or more pieces of information are to be displayed. Found in the Data group and the All Windows Forms group of the Toolbox. Displays a table with column headers. 22

DataGridView Control (continued) 23 DataGridView control

DataSource Method When the Select clause of a query contains two or more items, the pair of statements dgvGrid.DataSource = queryName.ToList dgvGrid.CurrentCell = Nothing displays the items of data in a DataGridView control. (The second statement, which is optional, keeps all cells unhighlighted.) 24

DataGridView Headers By default the rows have blank headers and the column headers contain the names of the items in the Select clause. 25 row headers column headers

DataGridView Headers (cont.) Row headers can be removed by setting the RowHeadersVisible property of the DataGridView control to False. A column header can be customized with a statement such as dgvGrid.Columns("yearFounded").HeaderText = "Year Founded" (see next slide) 26

DataGridView Headers (cont.) 27