Programming Right from the Start with Visual Basic .NET 1/e

Slides:



Advertisements
Similar presentations
Chapter 6, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 6 Sub Procedures And Functions.
Advertisements

Sub and Function Procedures
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 7: Sub and Function Procedures
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
VBA Modules, Functions, Variables, and Constants
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 4 The Fundamentals of VBA, Macros, and Command Bars.
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.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Apply Sub Procedures/Methods and User Defined Functions
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
IE 212: Computational Methods for Industrial Engineering
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
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 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
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.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
Chapter 6 Sub Procedures
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
1.
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.
Visual Basic Programming I 56:150 Information System Design.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
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 Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine.
Object-Oriented Programming: Classes and Objects.
Sub Procedures And Functions
Unit 2 Technology Systems
A variable is a name for a value stored in memory.
Programming in visual basic .net Visual Basic Building Blocks
IS 350 Application Structure
Chapter 1: An Introduction to Visual Basic 2015
Microsoft Visual Basic 2005: Reloaded Second Edition
Visual Basic 2010 How to Program
Chapter Eleven Handling Events.
JavaScript Syntax and Semantics
Chapter 4: The Selection Structure
2. Understanding VB Variables
Using Procedures and Exception Handling
Variables and Arithmetic Operations
Chapter 4 - Visual Basic Schneider
VISUAL BASIC.
Visual Basic .NET BASICS
Microsoft Visual Basic 2005 BASICS
Chapter 6 Sub Procedures
CIS16 Application Development and Programming using Visual Basic.net
CS285 Introduction - Visual Basic
Chapter 7: Using Functions, Subs, and Modules
Arrays.
Object-Oriented Programming: Classes and Objects
CIS16 Application Development and Programming using Visual Basic.net
Topics Introduction to Functions Defining and Calling a Function
Methods.
CIS16 Application Development and Programming using Visual Basic.net
Chapter 8 - Functions and Functionality
Presentation transcript:

Programming Right from the Start with Visual Basic .NET 1/e 9 Procedures and Arrays Programming Right from the Start with Visual Basic .NET 1/e

Objectives Understand the different types of variable scope Understand the three types of procedures in VB. NET Explain the similarities and differences between function and sub procedures

Objectives (cont.) Explain the relationship between arguments and parameters Distinguish between an array element and an array index Understand how to declare, reference, and resize an array

Objectives (cont.) Understand how to declare and use a structure array Understand how to declare and use a control array Understand how to work with KeyPress events Successfully write Windows applications involving procedures and arrays

9-1 Understanding Procedures A procedure is a block of statements that begins with a declaration statement and concludes with an End statement. Procedures allow for modular programming, a methodology whereby long programs are divided into numerous small procedures that are based on logical activities.

9-1 Understanding Procedures (cont.) Information can be passed to and from procedures by means of arguments and parameters. An argument is a value passed from the calling code to the procedure. A parameter is a variable listed in the formal procedure declaration that receives the argument.

9-2 Event Procedure An event procedure (or event handler) is a procedure containing code that is executed in response to an event. The sender parameter provides a reference to the object that raised the event. The second parameter is an object whose type depends on the event that is being handled.

9-3 Sub Procedure A sub procedure (or subroutine) contains developer code to perform a logical action. A sub procedure can be used as a container for code that is called multiple times. To call a sub procedure, reference the sub procedure name.

9-4 Function Procedure A function procedure (or function) is identical to a sub procedure, except that a function returns a value. The value the function sends back is called its return value. The Return statement is used to return a value from a function and return control back to the code that called the function.

9-5 Variable Scope When you declare a variable, you also define its scope. The scope of a variable is the region of code in which that variable may be directly referenced. It is determined by where you place the declaration and what keywords you use to declare it.

Local Scope A local variable is a variable declared inside a procedure. Local variables can only be referenced within the defining procedure. A local variable is destroyed when the procedure is finished executing.

Module Scope A module variable is declared at the module level outside of any procedure. Module scope variables are typically denoted by adding a lowercase m to the beginning of the variable name. Module level variables may be referenced by any procedure in the module.

9-6 Working with Arrays An array is a variable that holds multiple values. The values stored in an array are called the elements of the array. Each element in the array is distinguished by a unique number called the index (or subscript).

9-6 Working with Arrays (cont.) The first element of an array is always index 0. The last element of the array is called the upper bound and can be obtained by the UBound function. The number of elements in the array is always one more than the upper bound and can be obtained by the Length method.

Declaring an Array Array declarations use the keyword Dim followed by the array name followed by the array’s upper bound in parentheses. Dim ArrayName(upperbound) As datatype The elements of an array must all be of the same type, and this type is called the element type of the array.

Referencing an Array To reference an element of an array, you must specify both the name of the array and the index into the array. ArrayName(index) It is common to use For…Next loops and arrays together.

ReDim Statement After you declare an array, you can change its size (but not its type) by using the ReDim statement. ReDim [Preserve] ArrayName(NewArraySize) You will typically use ReDim to make an array larger. You can use the Preserve keyword to save the current contents.

Array.Sort Method When you declare an array variable, it inherits functionality from a general Array class. The Array.Sort method will sort the elements of an array.

9-7 Structure Arrays An array is a variable that holds multiple elements of the same type. A structure provides a means of combining several different variables into a single type, which can then be stored as an array element. Each variable declared inside the structure is called a member.

9-8 Control Arrays A control array is an array of Windows Form controls such as text boxes, labels, or buttons. Control arrays allow a developer to write a small amount of code that affects a potentially large number of GUI elements. Dim ArrayName(arraysize) As ControlType

9-9 KeyPress Event The KeyPress event is useful for capturing keystroke data as it would appear in a text box. The second argument, e, is a KeyPressEventArgs object, which exposes only two properties: Handled and KeyChar.

9-9 KeyPress Event (cont.) The KeyChar property is the character that corresponds to the key pressed. Handled is a Boolean value that you set to True to tell the form engine that you have already processed the event and that the engine should take no further action.

Chapter Summary A procedure is a set of instructions that perform a specific task. An argument is a means of sharing information between the calling program and a procedure. Modular programming involves breaking your application into procedures of logical units.

Chapter Summary (cont.) There are three types of procedures: event procedures, sub procedures, and function procedures. Event procedures contain code for responding to user or system events. Sub procedures are created by the developer to perform a logical series of actions.

Chapter Summary (cont.) Functions are identical to subroutines, except that functions return values. A variable declared in a procedure has local scope and can only be referenced within that procedure. A variable declared outside of any procedure is a module level declaration.

Chapter Summary (cont.) An array is a variable that holds multiple values. After an array has been declared, its size can be changed using the ReDim statement. The Array.Sort method will sort the contents of an array.

Chapter Summary (cont.) A structure provides a means of combining several different variables into a single type. A control array is an array of controls, such as buttons or labels. The KeyPress event is good for capturing keystroke data as it would appear in a text box.

Programming Right from the Start with Visual Basic .NET 1/e 9 Procedures and Arrays Programming Right from the Start with Visual Basic .NET 1/e