Working with Numeric Variables (Unit 6) Visual Basic for Applications.

Slides:



Advertisements
Similar presentations
Microsoft Office XP Microsoft Excel
Advertisements

Microsoft Office Illustrated Fundamentals Unit H: Using Complex Formulas, Functions, and Tables.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
Tutorial 8: Developing an Excel Application
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
Tutorial 7: Using Advanced Functions and Conditional Formatting
1.
String Variables Visual Basic for Applications 4.
The Numeric Variables Lecture 7 08/01/06 Dan Rao.
Using Objects and Properties
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 2 1 Microsoft Office Excel 2003 Tutorial 2 – Working With Formulas and Functions.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Data types and variables
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Chapter 2 Data Types, Declarations, and Displays
Chapter 7: Sub and Function Procedures
1 Computing for Todays Lecture 8 Yumei Huo Spring 2006.
Concepts of Database Management Sixth Edition
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Objectives You should be able to describe: Data Types
Chapter 3: Using Variables and Constants
Using the Select Case Statement and the MsgBox Function (Unit 8)
XP Abdul Hameed 1 Microsoft Office Excel 2013 Tutorial 2 – Working With Formulas and Functions.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall1 Exploring Microsoft Office Access Committed to Shaping the Next Generation.
Chapter 4: The Selection Structure
Object Variables Visual Basic for Applications 3.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
© 2002 ComputerPREP, Inc. All rights reserved. Excel 2000: Database Management and Analysis.
Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Using Visual Basic for Applications (VBA) – Project 8.
Using the selection structure (Unit 7) Visual Basic for Applications.
Numeric Variables Visual Basic for Applications 6.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Chapter 4: The Selection Structure
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
Representing Data: Constants and Variables CHAPTER THREE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
The Object Model Visual Basic for Applications 2.
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.
Introduction to Programming with RAPTOR
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.
1 Chapter 3: Customize, Analyze, and Summarize Query Data Exploring Microsoft Office Access 2007.
Working with Date Variables (Unit 5)
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
XP 1 Microsoft Office Excel 2003 Working With Formulas and Functions.
Advanced Repetition Structure and String Functions (Unit 10) Visual Basic for Applications.
XP 1 ﴀ New Perspectives on Microsoft Office 2003, Premium Edition Excel Tutorial 2 Microsoft Office Excel 2003 Tutorial 2 – Working With Formulas and Functions.
Microsoft Office 2013 ®® Calculating Data with Formulas and Functions.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Microsoft ® Excel ® 2013 Enhanced Excel Tutorial 3 Calculating Data with Formulas and Functions.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Excel Tutorial 8 Developing an Excel Application
Developing an Excel Application
Using Complex Formulas, Functions, and Tables
Microsoft Office Illustrated Fundamentals
Presentation transcript:

Working with Numeric Variables (Unit 6) Visual Basic for Applications

Objectives  In this unit, you will learn how to:  Reserve a numeric variable  Perform calculations using arithmetic operators  Add a list box to an Excel worksheet  Use the Excel VLookup function in a procedure  Search a table in Word  Refer to the Access ADO object model in code  Use the Recordset Object’s Find method

Concept Lesson: Discussing numeric variables  Use Dim statements to reserve a procedure-level numeric variable, which is a memory cell that can store a number only  Variables assigned either the Integer or the Long data type can store integers, which are whole numbers  The differences between the two data types are in the range of numbers each type can store and the amount of memory each type needs to store the numbers  Open VBE and search for Data Type Summary

Data Types Used to Reserve Numeric Variables Exhibit 6-1: The datatypes used to reserve numeric variables Search for “Data Type Summary” in VBE help box

Reserving a Procedure-level Numeric Variable  The memory requirement of a data type is an important consideration when coding a procedure  Long data type uses 4 bytes of memory, while the Integer data type uses only 2 bytes Exhibit 6-2: Some examples of Dim statements that reserve numeric variables

Assigning a Numeric Literal Constant to a Numeric Variable  A numeric literal constant is simply a number  A numeric literal constant cannot contain a letter, except for the letter E, which is used in exponential notation  Numeric literal constants cannot contain special symbols, such as the % sign, the $ sign, or the comma  They also cannot be enclosed in  quotation marks (“”)  or number signs (#),

Assigning a Numeric Literal Constant to a Numeric Variable Exhibit 6-3: Some examples of valid and invalid numeric literal constants Exhibit 6-4: Some examples of assignment statements that assign numeric literal constants to variables

Assigning a Numeric Expression to a Numeric Variable  Numeric expressions can contain items such as numeric literal constants, variable names, functions, and arithmetic operators  The precedence numbers represent the order in which the arithmetic operations are processed in an expression  You can use parentheses to override the order of precedence because operations within parentheses always are performed before operations outside of parentheses

Assigning a Numeric Expression to a Numeric Variable  When you create a numeric expression that contains more than one arithmetic operator, keep in mind that VBA follows the same order of precedence as you do when evaluating the expression Exhibit 6-5: The arithmetic operators and their order of precedence

Examples of Assignment Statements Containing Numeric Expressions Exhibit 6-6: Some examples of assignment statements containing numeric expression

Summary To reserve a procedure-level numeric variable:  Use the Dim statement. The syntax is  Dim variablename As datatype where variablename represents the name of the variable (memory cell) and datatype is the type of data the variable can store  Variable names must begin with a letter and they can contain only letters, numbers, and the underscore To assign a value to a numeric variable:  Use an assignment statement in the following syntax: variablename=value

Excel Lesson: Using numeric variables in Excel Open Jake’s workbook and view the Paradise Electronics price list.

Creating a List Box  A list box is one of several objects, called controls, that can be added to a worksheet  You typically use a list box to display a set of choices from which the user can select only one  List boxes help prevent errors from occurring in the worksheet  To add a list box control to the worksheet, use the Control Toolbox toolbar

Inserting Controls  You should enable Developer tab in Office 2007 to insert Controls  There are two types of controls:  Form Controls  ActiveX Controls  Form controls were the original controls and are much more simple  ActiveX controls offer more formatting properties  MS does not include ActiveX controls for the Mac

Control Toolbox Toolbar (Search for Overview of Form Controls) Exhibit 6-7: The Control Toolbox toolbar

Creating a List Box  To change the value assigned to several of the list box’s properties, use the Properties window  The Object box, located immediately below the Properties window’s title bar, displays the name and type of the selected object Exhibit 6-8: The Properties window

Creating a List Box  The Properties list, which can be displayed either alphabetically or by category, has two columns  The right column, called the Settings box, displays the current value, or setting, of each of those properties

List Box Control Drawn on the Worksheet Exhibit 6-9: The list box drawn on the worksheet

Coding the List Box’s DblClick Event Procedure A list box’s DblClick event procedure occurs when the user double-clicks an item in the list Exhibit 6-10: The pseudocode for the list box’s DblClick event procedure

Variables Used by the List Box’s DblClick Event Procedure Exhibit 6-11: The variables used by the list box’s DblClick event procedure

Using the Excel VLookup Function in a Procedure  You can use the VLOOKUP function to search the first column of a range of cells, and then return a value from any cell on the same row of the range.  When range_lookup is True (default) the VLookup function  performs a case-insensitive approximate search  stops when it reaches the largest value that is less than or equal to the lookup_value

Syntax of the VLookup Function Exhibit 6-12: The syntax of the Vlookup function

Examples of the VLookup Function Exhibit 6-13: Some examples of the Vlookup function

Word Lesson: Using numeric variables in Word  Open Pat’s document and view the UpdateMembership procedure.

Pseudocode for the UpdateMembership Macro Exhibit 6-14: The pseudocode for the Updatemembership procedure

Variables Used by the UpdateMembership Procedure Exhibit 6-15: The variables used by the UpdateMembership procedure

Searching a Table In Word, you can search a column in a table first by selecting the column, and then using the Execute method of the Find object to locate the desired value

Moving the Insertion Point to the Beginning of the Document  You can use the Selection object’s HomeKey method to move the insertion point to a different area in the document  The HomeKey method, whose syntax is expression.HomeKey Unit:=unit, corresponds to the functionality of the Home key on your keyboard  In Microsoft Word, a story is defined as an area of a document that contains a range of text that is distinct from other areas of text in the document

Using numeric variables in Access The ADO Object Model  The ADO (ActiveX Data Objects) object model contains all of the objects needed to manage the records contained in one or more tables Exhibit 6-16: A portion of the ADO object model showing the most commonly used ADO objects

The ADO Object Model  A Connection object represents the physical connection between an Access database and a data provider, which is a set of complex interfaces that allows ADO objects to use the data stored in a database  Immediately below the Connection object in the ADO object model is the Recordset object, which represents either all or a portion of the records (rows) contained in one or more tables

Coding the PaymentUpdate Procedure  Begin by opening this database and viewing the Payments table  Open Professor Martinez’s database and view the Payments table.

Pseudocode for the PaymentUpdate Procedure Exhibit 6-17: The pseudocode for the PaymentUpdate procedure

Variables Used by the PaymentUpdate Procedure Exhibit 6-18: The variables used by the PaymentUpdate procedure

Using the Recordset Object’s Open Method  You use the Recordset object’s Open method to open a recordset  The syntax of the Open method is recordset.open Source:=datasource, ActiveConnection:=connection, CursorType:= cursortype, LockType:=locktype, where recordset is the name of a Recordset object variable, datasource specifies the data source, and connection is the name of a Connection object variable

Valid Constants for the Open Method’s CursorType and LockType Arguments Exhibit 6-19: The valid constants for CursorType and LockType arguments

Using the Recordset Object’s Open Method  The cursortype and locktype arguments in the syntax can be one of the constants  The LockType argument prevents more than one user from editing a specific record at the same time by locking the record, making it unavailable to other users

Using the Recordset Object’s Find Method You can use the Recordset Object’s Find method to search for a value contained in a field in the recordset The syntax of the Find method is recordset.Find Criteria:=criteria

Examples of Using the Find Method to Search the rstPays Recordset Exhibit 6-20: Some examples of using the Find method to search the rstPays recordset