Arrays. Overview u General Discussion  Uses  Structure  Declaration u Searching u Control Arrays.

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

Chapter 10 Introduction to Arrays
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.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
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 9 Introduction to Arrays
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
Lec4 P 1 CP2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 4 Back To Index v Iteration - Looping v Arrays.
User-defined Data Types VB provides programmers with the ability to create user-defined types. User-defined Types are collections of related variables.
5.05 Apply Looping Structures
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
ISAT 252 Introduction to Arrays. Should have read 2 Chapter 8 –pp , and pp
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Processing Arrays Lesson 8 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
IE 212: Computational Methods for Industrial Engineering
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Using Arrays and File Handling
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Chapter 17: Arrays Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Chapter 8 Arrays Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Week Arrays, Timers, and More 9. 2 Introduction Arrays are like groups of variables that allow you to store sets of similar data A single dimension array.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
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.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Fundamentals of GUI Programming. Objectives: At the end of the session, you should be able to: describe the guidelines that are used for creating user-friendly.
Arrays Chapter 8. Chapter 8 - Part 12 Variable and Variable Array Variable Stores only one value Variable Array Variable that has 1 symbolic name but.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
Arrays1 From time to time an object (a variable, a picture, a label or a command) does not serve as well as a set of objects of a similar kind addressed.
Applications Development
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
1.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter Arrays, Timers, and More 8.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
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.
Arrays and others. Annoucement Today’s office hour move to Friday 1:00PM to 3:00PM Today’s office hour move to Friday 1:00PM to 3:00PM Today Today  Call.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
Arrays Chapter 8. Overview u General discussion u Variable arrays u Control arrays u Multi-dimensional variable arrays  Two-dimensional  Three-dimensional.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
Visual Basic CDA College Paphos Campus COM123 Visual Programming 1 Lecture: Charalambous Sotiris Week 8: COM123 Visual Programming 1 Lecture: Charalambous.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Chapter 9 Introduction to Arrays Fundamentals of Java.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Programming Right from the Start with Visual Basic .NET 1/e
IS 350 Arrays.
Single Dimensional Arrays
2. Understanding VB Variables
Using Procedures and Exception Handling
Variables and Arithmetic Operations
Arrays.
CIS16 Application Development and Programming using Visual Basic.net
To understand what arrays are and how to use them
Presentation transcript:

Arrays

Overview u General Discussion  Uses  Structure  Declaration u Searching u Control Arrays

Arrays u From time to time an object (a variable, a picture, a label or a command) does not serve as well as a set of objects of a similar kind addressed with a common name. u For example, in the grade point calculator, rather than having hamburgers, fries and drinks each with its own price and quantity measures, we might better describe the situation as an array of elements

3 Data Arrays u A variable like Stuff defines a data object into which a single quantity can be placed u A variable like Product defines a data object into which an array of information can be placed Product Stuff

Arrays u Arrays are useful for when there are many instances of similar data u Instead of ten integer variables holding ten values, a single array can handle all ten intd intcinte intj intf intb inta inti inth intg intArray

Arrays u Each variable location in an array is called an element u Use Dim statement to create, define dimension and type Dim intArray(1 to 10) as Integer creates the structure below u Treat as normal variables; Reference using subscripts: intArray(4) = “114” intArray 114

Arrays u Arrays allow programmers to write code once, but have it applied to many different data elements u Compare adding all the integers stored in the variables… intd intcinte intj intf intb inta inti inth intg intArray intSum = inta + intb + intc _ + intd + inte + intf + intg _ + inth + inti + inj

Arrays u Arrays allow programmers to write code once, but have it applied to many different data elements u …to adding all the elements of the array intd intcinte intj intf intb inta inti inth intg intArray For intI = 1 to 10 intSum = intSum + intArray(intI) Next

Arrays u Arrays come in different dimensions. u Two dimensional arrays  require two subscripts  elements are listed (row, column) u Example  DIM intSales(1 to 3, 1 to 4) as integer u What is intSales(2, 3)?

Arrays u Three dimensional arrays  require three subscripts u Example  Dim intSales (1 to 3, 1 to 4, 1 to 2) as Integer So the number 2134 is found where? the number 4521 is ______ the number 1402 is ______ the number 3425 is ______

Parallel Arrays u Dim strName (1 to 5) as String u Dim intSales (1 to 5) as Integer u So, if we know that Smith is in strName(2), we also know his or her sales is in intSales(2) strName intSales Jones Smith Frank Able Zean

Creating Arrays u Dim statement  Array name; Dimensions; Bounds; Type Dim strName (1 to 3, 1 to 4) as String u Using  Any integer literal or variable can be used to subscript  Must stay within the bounds  Must have the correct number of subscripts  Must assign the correct type of data  Given: Dim strName (1 to 3, 1 to 4) as String  Is strName (0,0) = “Jones” valid?  Is strName (2) = “Smith” valid?  Is strName (4,3) = “Larry” valid?  Is strName(3,4) = 1402 valid?

Searching Arrays strTarget = “Q” intFound = 0 For intI = 1 to 10 If strTarget = strArray(intI) Then intFound = intI Exit For End If Next strArray A F S V W Q Z X Y L Searching implies looking for a target A simple sequential search looks through the array for the target

Dynamic Arrays u VB allows a programming to re-dimension arrays during the run of the program. u Rules for Dynamic Arrays  Use empty dimension list: intArray() as Integer  Use ReDim to assign dimensions: ReDim intArray (1 to intN, 1 to 2)  Use ReDim to change Bounds ReDim intArray (1 to (intN + 10), 1 to 3)  Use Preserve keyword to save data in array ReDim Preserve intArray(1 to intN, 1 to 5) Preserve only allows changes in the last dimension

Control Arrays u VB allows the programmer to create arrays of controls on the form  Just as there are data arrays, there may be arrays of objects, such as command buttons, labels or picture boxes  An array of labels might be made with one label for each product, or for each price  An array of command might be made to handle adding products u Characteristics  Name with subscripted elements .Index property is the subscript

Control Arrays u Create an toolbox object, perhaps a command button, changing its (name) and caption.

Control Arrays 1.Copy and paste the object (Ctrl-C)(Ctrl-V) or Edit/Copy then Edit/Paste 2.The message “Do you want to create a control array?” appears. Answer “yes” 3.Type Edit/Paste or (Ctrl-V) several more times to make an array of commands

Control Arrays u The Properties Window shows it all. u Note that the 4th command created is shown as “cmdButn(3)”

Control Arrays u Arrange the buttons on the form as desired u Double clicking on any one of them opens the code window

Control Arrays The event handler is a bit strange. There is now a “parameter” inside the normally blank parentheses: Private Sub cmdButn_Click(Index As Integer) lblOutput.Caption = "## " & Index & " ##" End Sub

Control Arrays u Run the process u Click each button u Observe the effect

Control Arrays u Using the same procedure, you can make arrays of labels, or of pictures, or of check boxes, etc. u You can change the GPA calculator program to make arrays of products, commands, product counts, and total costs

Summary u Arrays are sets of variables know as elements u These elements operate just like simple variables u Arrays are created with a DIM statement that defines; boundaries, dimensions and type u When referencing elements in an array, you must have the correct number of subscripts and their values must be within the bounds of the dimensions u The operation of looking through an array for a “target” is called searching