Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Arrays.
Pemrograman VisualMinggu …7… Page 1 MINGGU Ke Tujuh Pemrograman Visual Pokok Bahasan: Arrays Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
VBA Modules, Functions, Variables, and Constants
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
 2006 Pearson Education, Inc. All rights reserved Arrays.
An Object-Oriented Approach to Programming Logic and Design Chapter 7 Arrays.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
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.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
 Pearson Education, Inc. All rights reserved Arrays.
VB .NET Programming Fundamentals
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Java Unit 9: Arrays Declaring and Processing Arrays.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
IE 212: Computational Methods for Industrial Engineering
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.
Using Arrays and File Handling
 2006 Pearson Education, Inc. All rights reserved Arrays.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
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.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
 Pearson Education, Inc. All rights reserved Arrays.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
 2005 Pearson Education, Inc. All rights reserved. 1 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.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
JavaScript, Fourth Edition
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
CHAPTER 9 PART II. MULTIDIMENSIONAL ARRAYS Used to represent tables of values arranged in rows and columns. Table element requires two indexes: row and.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
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.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
 2005 Pearson Education, Inc. All rights reserved Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
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.
Microsoft Visual Basic 2005: Reloaded Second Edition
JavaScript: Functions.
Object Oriented Programming in java
MSIS 655 Advanced Business Applications Programming
Arrays.
CIS16 Application Development and Programming using Visual Basic.net
Presentation transcript:

Case, Arrays, and Structures

Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring and Allocating Arrays –Array Declaration Example –Passing Arrays to Procedures –Example Passing Arrays –Multidimensional Rectangular and Jagged Arrays –For Each/Next Repetition Structure –Example Multidimensional Array with Each/Next Repetition  Structures –Example of a Structure –Structures and Classes –Structure Variables  Structures and Arrays

Case Structure  Best alternative for testing a single variable or expression for multiple values  Any decisions coded with nested If statements can also be coded using Case structure  Case Structure is simpler, cleaner, more efficient than the nested If

Select Case General Form (also notice indenting) Select Case expression Case ConstantList [ code to run] [Case ConstantList [ code to run]] [Case Else ] [code to run]] End Select If expression=value in constant list If expression values in any of the preceding constant lists ** Case Else is an optional clause

Select Case - Numeric Value Example 1 Select Case intScore Case Is > =100 lblMsg.Text="Excellent Score" Case 80 to 99 lblMsg.Text="Very Good" Case 60 to 79 lblMsg.Text=“Average Score" Case Else lblMsg.Text="Improvement Needed" End Select

Select Case - String Value Example Select Case txtTeam.Text.ToUpper( ) Case "TIGERS" (Code for Tigers) Case "LEOPARDS" (Code for Leopards) Case "COUGARS", "PANTHERS" (Code for Cougars and Panthers) End Select

About Arrays  Arrays are data structures consisting of data items of the same type  Position number –Values that indicate specific locations within arrays –The first element in every array is the zero element  Length property –Every array in Visual Basic “knows” its own length through the Length property  GetUpperBound method –Returns the index of the last element in the array –The value returned by this GetUpperBound is one less than the value of the array’s Length property

Arrays

Declaring and Allocating Arrays Generally speaking, there are two ways to declare arrays: 1. Intitializer lists (if you know the values of the array during coding) 2. Declare and populate method (if you do not know the values of the array elements during coding because they will be dynamically loaded to the array) The amount of memory required by an array depends on the length of the array and the size of the data type of the elements in the array

Array Declaration Example

Passing Arrays to Procedures  Passing the Array –Specify the name of the array without using parentheses –Every array object “knows” its own upper bound Do not need to pass the upper bound of the array as a separate argument –In Visual Basic, arrays always are passed by reference  Receiving the array –The procedure’s parameter list must specify that an array will be received

Example Passing Arrays

Multidimensional Rectangular and Jagged Arrays  Multidimensional arrays (multiple-subscripted) –Require two or more indices to identify particular elements  Rectangular arrays –Two indices, first identifies the element’s row, the second the elements column –A rectangular two-dimensional array with m rows and n columns is called an m-by-n array  Jagged arrays –Jagged arrays are maintained as arrays of arrays –Rows in jagged arrays can be of different lengths

For Each/Next Repetition Structure  For Each/Next –Provided to iterate through the values in a data structure, such as an array –Instead of a counter, For Each/Next uses a variable to represent the value of each element –Useful when the indices of the elements are not important –Particularly useful for looping through arrays of objects

Example Multidimensional Array with Each/Next Repetition

Structures  A structure is a combination of multiple fields of related data.  The Structure declaration cannot go inside a procedure  Structure statements are typically placed at the top with the module level declarations or in a separate class  Once you have created a structure, you can declare variables of the structure, just as if it were another data type

Example of a Structure

Structures and Classes  Structures and classes are similar in the following respects: 1.Both have members, including constructors, methods, properties, fields, constants, enumerations, and events. 2.Both can implement interfaces. 3.Both can have shared constructors, with or without parameters.  Structures and classes differ in the following particulars: 1.Structures are value types; classes are reference types. 2.All structure members are Public by default; class variables and constants are Private by default 3.Structure variable declarations cannot specify initializers, the New keyword, or initial sizes for arrays; class variable declarations can. 4.Structures implicitly inherit from the ValueType class and cannot inherit from any other type; classes can inherit from any class or classes other than ValueType. 5.Structures are not inheritable; classes are. 6.Structures are never terminated, so the common language runtime (CLR) never calls the Finalize method on any structure

Structure Variables  Once you have created a structure, you can declare procedure-level and module-level variables as that type. For example, you can create a structure that records information about a computer system, as in the following code:  You can now declare variables of that type, as follows:  To assign and retrieve values from the elements of a structure variable, you use the same syntax as you use to set and get properties on an object.

Structures and Arrays  A structure can contain an array as one of its elements  You access the values of an array within a structure the same way you access a property on an object  You can also declare an array of structures