VB Arrays Chapter 8 Dr. John P. Abraham Professor UTPA.

Slides:



Advertisements
Similar presentations
One Dimensional Arrays
Advertisements

VB PROJECT “PROJECT SAMPLES”. For Next Loops Design a VB program that displays in a picture box the first N multiples of an input integer Input 3 exam.
COPYRIGHT 2003: Dr. David Scanlan, CSUS OBJECTIVES: Explain the need for arrays. Coding an array. Basic algorithms: Largest, Smallest, Sum, Standard Deviation,
Data Structures & Algorithms
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Arrays Arrays are data structures consisting of data items of the same type. Arrays are ‘static’ entities, in that they remain the same size once they.
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
CHAPTER 6 Stacks Array Implementation. 2 Stacks A stack is a linear collection whose elements are added and removed from one end The last element to be.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
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.
Introduction to Programming with C++ Fourth Edition
Chapter 7 - Visual Basic Schneider1 Chapter 7 Arrays.
 2007 Pearson Education, Inc. All rights reserved C 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.
Data Structures Data structures permit the storage of related data for use in your program. –Arrays.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
Processing Arrays Lesson 8 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Topic 3 The Stack ADT.
Grade 12 Computer Studies HG
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
Chapter 11 Arrays Continued
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
# 1# 1 Searching andSorting What is selection sort? What is bubble sort? What is binary search? CS 105 Spring 2010.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
Neal Stublen Computer Memory (Simplified)  Remember, all programming decisions came down to a true or false evaluation  Consider.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Sorting & Searching Review. Selection Sort 1. Find the smallest element 2. Move to the front of the array (swap with front) 3. Repeat Steps 1&2, but ignoring.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
PSU CS 106 Computing Fundamentals II VB Declarations HM 5/4/2008.
Other Variable Types Dim lab as String makes a box that can store a label tag Dim ColHead As String ColHead = “function” ColHead function Dim lab as Boolean.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley More About Array Processing 8.2 There Are Many Uses of Arrays and Many Programming.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Arrays An array is a data object that can hold multiple objects, all of the same type. We can think of an array as a storage box which has multiple compartments.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Arrays.
Processing Arrays Lesson 9 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
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.
Data Structures Arrays and Lists Part 2 More List Operations.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Arrays. Example Write a program to keep track of all students’ scores on quiz 1. Need a list of everyone’s score Declare 14 double variables? What about.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Arrays 1.
Visual Basic Fundamental Concepts
Stacks and Queues Chapter 4.
Chapter 7 Arrays.
CSCI 3327 Visual Basic Chapter 7: Data Manipulation in Arrays
Visual Basic..
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
CSCI 3327 Visual Basic Chapter 7: Arrays
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
CIS16 Application Development and Programming using Visual Basic.net
CS210- Lecture 3 Jun 6, 2005 Announcements
Random Access Files Dr. John Abraham.
Introduction to Computer Programming IT-104
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:

VB Arrays Chapter 8 Dr. John P. Abraham Professor UTPA

Arrays Multiple elements of the same data type. Most languages the number of elements are static and defined at declaration In VB arrays can be re-dimensioned at execution time. Single dim, two dim and multiple dim

Declaring an Array Declaration (different ways) –Dim grades as integer() –Grades = New Integer(0 to 9) {} {} initializer list –Grades = New Integer(9) {} –Dim grades() as Integer Declare and Initialize –Dim grades as Integer()={90,80,88,90,70}

Referring to an Element Name and position Grades(6) = 85 First element is 0 th 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 = Grades.GetUpperBound(0) Will give 9 (see the declaration) X= grades.GetLength(0) Will give 10

Explain abstract structures Card program explained Two intermediate assignments explained –Month conversion –Standard deviation

List Boxes explained List box –lstBoxMonths.Items.Add(monthNames(i)) Check List Box –chkLstBoxMonths.Items.Add(monthNames(i)) Combo Box with drop down –comboBoxMonths.Items.Add(monthNames(i))

Linear Search explained Dim searchMonth As String Dim found As Boolean searchMonth = txtMonthName.Text found = False : i = 1 While (Not (found)) And (i <= 12) If searchMonth = monthNames(i) Then found = True lblMonthNum.Text = i.ToString End If i += 1 End While

Splitting a string Dim grades() As String = Split(txtEnterGrade.Text, " ")

Passing Arrays Always as byVal (it is just a pointer to the 0 th 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

Card Game Two parts: text (string) and graphics. Realize you really do not move the string around, you work with the indices. For instance to display shuffled cards: For i = 1 to 52 Display OriginalDeck(shuffled(i)) Next

Sorting & Searching Array.Sort exists, but don’t use it. Sorting You need to implement it Don’t use the method sort comes with array class. You may use bubble sort or selection sort.

Bubble sort sorted = False While Not (sorted) sorted = True For i = 1 To j - 1 If CustomerName(i) > CustomerName(i + 1) Then Call swap(i) sorted = False End If Next i j = j - 1 Wend

Swap Private Sub swap(i) Dim tmp1 As String * 25 Dim tmp2 As String * 11 tmp1 = CustomerName(i) CustomerName(i) = CustomerName(i + 1) CustomerName(i + 1) = tmp1 tmp2 = CustomerTele(i) CustomerTele(i) = CustomerTele(i + 1) CustomerTele(i + 1) = tmp2 End Sub

Searching Linear search Binary search

Dim Lookfor As String * 25 Dim first, last, middle As Integer Dim nfound As Boolean LblName.Caption = "": LblTele.Caption = "" Lookfor = TxtSearch.Text nfound = False first = 1: last = Index While (Not (nfound) And first <= last) middle = (first + last) \ 2 If RTrim(Lookfor) = RTrim(CustomerName(middle)) Then nfound = True LblName.Caption = CustomerName(middle) LblTele.Caption = CustomerTele(middle) ElseIf Lookfor < CustomerName(middle) Then last = middle - 1 Else: first = middle + 1 End If Wend If Not (nfound) Then LblName.Caption = "Name not in list" TxtSearch.Text = ""

Using an array for a stack Keep track of top. Increase it before adding (push), Decrease it after taking (pop). Push or Pop only to or from the top. Examine the stack to see if it is empty or full For example, if stack.top < 0 it is empty. You may choose not to use the 0 th location for data, then you can say it is empty when stack.top is zero.