Advanced Repetition Structure and String Functions (Unit 10) Visual Basic for Applications.

Slides:



Advertisements
Similar presentations
1.
Advertisements

Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation.
VBA Modules, Functions, Variables, and Constants
String Variables Visual Basic for Applications 4.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
Using Objects and Properties
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
Adding Automated Functionality to Office Applications.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
1.
Using the Select Case Statement and the MsgBox Function (Unit 8)
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
Object Variables Visual Basic for Applications 3.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Using the selection structure (Unit 7) Visual Basic for Applications.
Working with Numeric Variables (Unit 6) Visual Basic for Applications.
Numeric Variables Visual Basic for Applications 6.
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Working with option button, check box, and list box controls Visual Basic for Applications 13.
Date Variables Visual Basic for Applications 5. Objectives n In this tutorial, you will learn how to: n Reserve a Date variable n Use an assignment statement.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Chapter 6: The Repetition Structure
Tutorial 6 The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
Working with Date Variables (Unit 5)
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
Selecting Data Database Administration Fundamentals LESSON 3.1a.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Chapter 13 Do It, Then Ask Permission (Posttest Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 14 Do It, Then Ask Permission.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Microsoft Visual Basic 2008: Reloaded Third Edition
VBA - Excel VBA is Visual Basic for Applications
The Selection Structure
Repeating Program Instructions
Making Decisions in a Program
Microsoft Visual Basic 2005: Reloaded Second Edition
Exploring Microsoft Excel
CIS 16 Application Development Programming with Visual Basic
Chapter 8: More on the Repetition Structure
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS16 Application Development and Programming using Visual Basic.net
Presentation transcript:

Advanced Repetition Structure and String Functions (Unit 10) Visual Basic for Applications

Objectives  In this unit, you will learn how to:  Perform repetition using the Do…Loop statement  Manipulate a string using string functions  Search for a string within another string  Sort a table in Word using the Sort method

Concept Lesson: More on Repetition Structure  You also can use the repetition structure to repeat one or more instructions until some condition is met  You can use the VBA Do…Loop statement to code that type of repetition structure

The Do…Loop Statement  You can use the VBA Do…Loop statement to code a repetition structure that repeats its instructions either while some condition is true or until some condition becomes true  VBA also has another version of the Do…Loop statement, where the {While|Until} appears in the Loop clause rather than in the Do clause  The Do…Loop statement begins with the Do clause and it ends with the Loop clause  The {While | Until} indicates that you can select only one of the keywords appearing within the braces

Syntax and Examples of the Do…Loop Statement Exhibit 10-1: The syntax and examples of the Do…Loop statement

The VBA String Manipulation Functions  VBA provides a set of functions that makes string manipulation an easy task  In this lesson, you will learn how to use four of the most frequently used string manipulation functions:  Left  Right  Mid  Instr

The Left and Right Functions  The Left and Right functions return one or more characters from a string, starting at either the left or right end of the string Exhibit 10-2: The syntax and examples showing the Left and Right functions

The Mid Function  The Mid function, which has the syntax Mid(String:=string, Start:=start[,Length:= length]), returns length number of characters from the string, beginning with the start character Exhibit 10-3: The syntax and examples of the Mid function

The Instr Function  You can use the Instr function to search a string to determine if it contains another string  The syntax of the Instr function is Instr(start, string1, string2 [, compare]) Exhibit 10-4: The syntax and examples of the Instr function

Summary To use the Do…Loop statement to code the repetition structure:  Use the syntax shown in Exhibit 10-1, where condition, which must evaluate to either True or False, can contain variables, constants, functions, mathematical operators, comparison operators, and logical operators To return characters from a string:  Use the Left, Right, or Mid functions  The Left function, the syntax of which is Left(String:=string, Length:=length), returns the left-most length number of characters from the string

Summary To return characters from a string:  The Right function, the syntax of which is Right(String:=string, Length:=length), returns the right-most length number of characters from the string  The Mid function, the syntax of which is Mid(String:=string, Start:=start[, Length:=length]), returns length number of characters from the string, beginning at position start

Summary To search a string if it contains another string:  Use the Instr function, the syntax of which is Instr(start, string1, string2[, compare]). The Instr function does not support the use of named arguments  Start is a numeric expression that sets the starting position for the search  If string2 is contained within string1, then the Instr function returns the starting position of string2

Excel Lesson: Viewing the Consultants Worksheet and the BreakNameApart Procedure  Before creating the macro that will separate each consultant’s full name into his or her first and last name, view the workbook, and the code template for the BreakNameApart procedure

Pseudocode for the BreakNameApart Procedure Exhibit 10-5: The pseudocode for the BreakNameApart procedure

Viewing the Consultants Worksheet and the BreakNameApart Procedure  The BreakNameApart procedure will use the intLocation variable to store the value returned by the Instr function, and it will use the shtConsult variable to store the address of the Consultants worksheet

Word Lesson: Viewing the Guest Document  Before creating the procedure that will sort the list and then remove any duplicate names, view the document and the code template for the SortAndRemoveDuplicates procedure

Sorting a Table  You can use the Table object’s Sort method to sort the entries in a table in either ascending or descending order  The Sort method’s ExcludeHeader argument, which can be set to either the Boolean value True or the Boolean value False, controls whether the first row in the table is sorted along with the remaining table rows  You can sort the table entries based on the values stored in one, two, or three different columns

Sorting a Table  You use the SortFieldType, SortFieldType2, and SortFieldType3 arguments to indicate the type of data contained in the FieldNumber, FieldNumber2, and FieldNumber3 columns, respectively Exhibit 10-6: The syntax and examples of the Table object’s Sort method

Pseudocode for the SortAndRemoveDuplicates Procedure Exhibit 10-7: The pseudocode for the SortAndRemoveDuplicates procedure

Coding the SortAndRemoveDuplicates Procedure  The SortAndRemoveDuplicates procedure will use the intRow variable in a Do…Loop statement that repeats its instructions for each table row that contains guest information  This procedure will use the strCurrentName and strPreviousName variables to store the names entered in the current and previous rows, respectively, in the table

Access Lesson: Viewing the Database and the LocateInstructor Procedure  Before creating the macro that will display the names of instructors teaching a particular course, you will view the records contained in the database’s AdjunctFaculty table

Pseudocode for the LocateInstructor Procedure Exhibit 10-8: The pseudocode for the LocateInstructor procedure

Viewing the Database and the LocateInstructor Procedure  This procedure will use the String variable strCourseNum to store the course number entered by the user  It will use the String variable strFound to store the letter “Y”, indicating that the procedure located at least one instructor who teaches the course

Viewing the Database and the LocateInstructor Procedure  The cnnAdjFac and rstAdjFac object variables will be used to store the addresses of the Connection and Recordset objects, respectively

Viewing the Database and the LocateInstructor Procedure  You will use the Do…Loop statement along with the Recordset object’s EOF property to code the appropriate loop  The Recordset object’s EOF property returns the Boolean value True if the record pointer, which Access uses to keep track of the current record, is positioned after the last record in the recordset  Because a Recordset is an object rather than a collection, you cannot use the For Each…Next statement that you learned about in unit 9 to code the loop; however, you can use the For…Next statement