CSCI 3327 Visual Basic Chapter 7: Arrays

Slides:



Advertisements
Similar presentations
Visual Basic 2010 How to Program
Advertisements

Chapter 10 Introduction to Arrays
Lecture Roger Sutton CO331 Visual Programming 12: One-dimensional Arrays 1.
Chapter 8 Using Repetition with Loops and Lists. Class 8: Loops and Lists Write Do loops to execute statements repeatedly Write For loops to execute statements.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Flag Quiz Application Introducing One-Dimensional Arrays and ComboBox es.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
VB Arrays Chapter 8 Dr. John P. Abraham Professor UTPA.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Arrays 1.
7.1 Introduction Arrays Arrays are data structures consisting of data items of the same type “Static” entities They remain the same size once they are.
Arrays and Collections
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Chapter VII: Arrays.
Chapter 11 - JavaScript: Arrays
Sections 10.1 – 10.4 Introduction to Arrays
Chapter 6: Using Arrays.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Microsoft Visual Basic 2005: Reloaded Second Edition
CSCI 3327 Visual Basic Chapter 11: Files and Streams
Visual Basic 2010 How to Program
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
ARRAYS.
IS 350 Loops.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
Arrays, Collections and Repetition Part A – Arrays and Repetition
The University of Texas – Pan American
CSCI 3327 Visual Basic Chapter 7: Data Manipulation in Arrays
Visual Basic .NET BASICS
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
The University of Texas Rio Grande Valley
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I UTPA – Fall 2012 This set of slides is revised from lecture slides.
The University of Texas – Pan American
The University of Texas – Pan American
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Visual Basic 2010 How to Program
CSCI 3327 Visual Basic Review: Final Exam
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections UTPA – Fall 2012 This set of slides is revised from lecture slides.
Object Oriented Programming in java
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects – Exercises UTPA – Fall 2012 This set of slides is revised.
Introduction to Problem Solving and Control Statements
CSCI 3327 Visual Basic Review: Exam I
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
Arrays.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Arrays Topics Definition of a Data Structure Definition of an Array
CISC181 Introduction to Computer Science Dr
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
CIS16 Application Development and Programming using Visual Basic.net
Arrays October 6, 2006 ComS 207: Programming I (in Java)
Programming Logic and Design Fifth Edition, Comprehensive
Java: Variables, Input and Arrays
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
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.
Arrays Topics Definition of a Data Structure Definition of an Array
Introduction to Computer Programming IT-104
CSCI 3328 Object Oriented Programming in C# Review: Exam II
Lecture Set 9 Arrays, Collections, and Repetition
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays – Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof.
Presentation transcript:

CSCI 3327 Visual Basic Chapter 7: Arrays UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous lecture slides. – Xiang Lian

Objectives In this chapter, you will: Learn how arrays are used to store elements Get familiar with the declaration, initialization, and reference to elements of the array Know how to pass arrays to methods Learn how to use For Each … Next statement to iterate through elements in the array

Arrays An array is a group of variables (called elements) containing values that all have the same data type For most languages, the number of elements are static and defined at declaration In Visual Basic, arrays can be re-dimensioned at the execution time Single dim, two dim and multiple dim

Example of an Array The first element is the zeroth element C(0) -45 C(1) 6 C(2) C(3) 72 C(4) 34 C(5) 39 C(6) 98 C(7) -1345 C(8) 939 C(9) 10 C(10) 40 C(11) 33 The first element is the zeroth element The highest position number is array’s upper bound Array C on RHS: 11 Access array elements Use index (or subscript) E.g., C(8)

Declaring an Array Declaration (different ways) Dim Grades As Integer() Grades = New Integer(0 to 11) {} {} initializer list Grades = New Integer(11) {} Dim Grades() As Integer Declare and initialize with initializer lists Dim Grades() As Integer={90,80,88,90,70} Local type inference Dim Grades ={90,80,88,90,70}

Default Initialization When you do not provide initializer list, elements are initialized to default values Numeric primitive data type: 0 Boolean data type: False String data type: Nothing

Referring to an Element Name and position Grades(6) = 85 First element is 0th index (subscript) Index must be a nonnegative integer Index may have a calculated value like Grades(i+4*2) Know the difference between index and value stored there Sum = Grades(1) + Grades(2) + Grades(3)

Array is a Class Class is in System.Array X = C.GetUpperBound(0) -45 C(1) 6 C(2) C(3) 72 C(4) 34 C(5) 39 C(6) 98 C(7) -1345 C(8) 939 C(9) 10 C(10) 40 C(11) 33 Class is in System.Array X = C.GetUpperBound(0) Will give 11 (see the declaration) X= C.GetLength(0) Will give 12 X=C.Length

Example 7.2: InitializeArrays.vb URL: http://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/codeexamples.html GetUpperBound(0)

Example 7.3: SumArray.vb URL: For i = 0 To values.GetUpperBound(0) http://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/codeexamples.html For i = 0 To values.GetUpperBound(0) Total+= values(i) Next

Example 7.4: StudentPoll.vb URL: http://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/codeexamples.html IndexOutOf Range Exception Try … statements Catch ex As IndexOutOfRangeException 'handling exceptions End Try

Example 7.5: DiceStatistics.vb URL: http://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/codeexamples.html Summarize statistics of the dice CType

Example 7.6: Flag Quiz URL: Properties of ComboBox http://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/codeexamples.html Properties of ComboBox DropDownStyle: DropDownList (not editable) MaxDropDownItems: the maximum number of items displayed at one time CountriesComboBox.DataSource=countries 'array CountriesComboBox.Selected Index = 0 Replace method of String: country.Replace(" ","")

Passing Arrays Always as byVal (it is just a pointer to the 0th element) Declaration Dim scores(80) As Integer Function standardDeviation(ByVal scores() As Integer, ByVal numscores As Integer) As Double Call stdDev = standardDeviation(scores, numScores)

Manipulating Array Using Loops For i = 0 To scores.GetUpperBound(0) Total += scores(i) Next

For Each … Next Statement For Each grade In gradeArray Total += grade Next ----------------------------------------------------------- For Each grade As Integer In gradeArray