Numeric Variables Visual Basic for Applications 6.

Slides:



Advertisements
Similar presentations
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
Advertisements

Tutorial 7: Using Advanced Functions and Conditional Formatting
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
Using the Visual Basic Editor Visual Basic for Applications 1.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Chapter 2 Data Types, Declarations, and Displays
Chapter 7: Sub and Function Procedures
JavaScript, Third Edition
1 Computing for Todays Lecture 8 Yumei Huo Spring 2006.
Concepts of Database Management Sixth Edition
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
XP New Perspectives on Microsoft Excel 2002 Tutorial 2 1 Microsoft Excel 2002 Tutorial 2 – Working With Formulas and Functions.
XP Copyright 2003 Peter McDevitt 1 Microsoft Excel 2002 Lecture 2 – Working With Formulas and Functions.
Lesson 4 Cell Reference Formulas. Working with Cell References continued… Relative Cell Reference A relative cell reference means that the cell value.
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 © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
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.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
CHAPTER THREE Representing Data: Constants and Variables.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Using the selection structure (Unit 7) Visual Basic for Applications.
Working with Numeric Variables (Unit 6) Visual Basic for Applications.
Chapter 12: How Long Can This Go On?
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
Tutorial 8 Programming with ActionScript 3.0. XP Objectives Review the basics of ActionScript programming Compare ActionScript 2.0 and ActionScript 3.0.
Chapter 2: Using Data.
Representing Data: Constants and Variables CHAPTER THREE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
The Object Model Visual Basic for Applications 2.
Concepts of Database Management Seventh Edition
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.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
1 Chapter 3: Customize, Analyze, and Summarize Query Data Exploring Microsoft Office Access 2007.
Working with Date Variables (Unit 5)
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
XP 1 Microsoft Office Excel 2003 Working With Formulas and Functions.
Advanced Repetition Structure and String Functions (Unit 10) Visual Basic for Applications.
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 th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
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.
CHAPTER THREE Representing Data: Constants and Variables.
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.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Presentation transcript:

Numeric Variables Visual Basic for Applications 6

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

Concept Lesson: Reserving a Procedure-level Numeric Variable n Dim statements can be used to reserve a procedure-level numeric variable, which is a memory cell that can store a number only n Variables assigned either the Integer or the Long data type can store integers, which are whole numbers n 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 6

Data Types Used to Reserve Numeric Variables 6

Reserving a Procedure-level Numeric Variable n The memory requirement of a data type is an important consideration when coding a procedure n Long data type uses 4 bytes of memory, while the Integer data type uses only 2 bytes 6

Using an Assignment Statement to Assign a Value to a Numeric Variable n When variablename is the name of a numeric variable, a value can be a number, more technically referred to as a numeric literal constant, or it can be a numeric expression 6

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

Assigning a Numeric Literal Constant to a Numeric Variable 6

Assigning a Numeric Expression to a Numeric Variable 6 n Numeric expressions can contain items such as numeric literal constants, variable names, functions, and arithmetic operators n The precedence numbers represent the order in which the arithmetic operations are processed in an expression n 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 6 n 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

Examples of Assignment Statements Containing Numeric Expressions 6

Summary To reserve a procedure-level numeric variable: n Use the Dim statement. The syntax of the Dim statement 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 n 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: n Use an assignment statement in the following syntax: variablename=value 6

Excel Lesson: Viewing the Paradise Electronics Price List n To open Jake’s workbook and view the Paradise Electronics price list, use the steps on pages 338 and 339 of the textbook 6

Creating a List Box n A list box is one of several objects, called controls, that can be added to a worksheet n You typically use a list box to display a set of choices from which the user can select only one n List boxes help prevent errors from occurring in the worksheet n To add a list box control to the Computers worksheet, use the steps on pages 340 to 342 of the textbook 6

Control Toolbox Toolbar 6

Placement of Crosshair 6

List Box Control Drawn on the Worksheet 6

Creating a List Box 6 n To change the value assigned to several of the list box’s properties, use the steps on pages 343 to 347 of the textbook n The Object box, located immediately below the Properties window’s title bar, displays the name and type of the selected object

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

List Box Shown in the Correct Size 6

Coding the List Box’s DblClick Event Procedure n A list box’s DblClick event procedure occurs when the user double-clicks an item in the list 6

Variables Used by the List Box’s DblClick Event Procedure 6

Coding the List Box’s DblClick Event Procedure n To begin coding the DblClick event procedure, use the steps on pages 348 and 349 of the textbook 6

Code Window Showing the Additional Two Lines of Code 6

Using the Excel VLookup Function in a Procedure n You can use Excel’s VLookup function to search for, or “look up,” a value located in the first column of a vertical list, and then return a value located in one or more columns to its right n In the VLookup function’s syntax, lookup_value is the value to be found in the first column of table, which is the location of the range that contains the table of information n When range_lookup is True, or when the argument is omitted, the VLookup function performs a case-insensitive approximate search, stopping when it reaches the largest value that is less than or equal to the lookup_value 6

Syntax of the VLookup Function 6

Examples of the VLookup Function 6

Using the Excel VLookup Function in a Procedure n To complete the DblClick event procedure, use the steps on pages 353 and 354 of the textbook 6

Using the Excel VLookup Function in a Procedure n To test the list box’s DblClick event procedure, use the steps on pages 354 and 355 of the textbook 6

Word Lesson: Coding the UpdateMembership Procedure n Begin by opening this document and viewing the code template for the UpdateMembership procedure, which already has been inserted into a module n To open Pat’s document and view the UpdateMembership procedure, use the steps on pages 362 to 364 of the textbook 6

Membership Document 6

Pseudocode for the UpdateMembership Procedure 6

Variables Used by the UpdateMembership Procedure 6

Coding the UpdateMembership Procedure 6 n To begin coding the UpdateMembership procedure, use the steps on pages 365 and 366 of the textbook

Code Window Showing the Additional Two Lines of Code 6

Searching a Table n 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 n To continue coding the UpdateMembership procedure, use the steps on pages 366 to 368 of the textbook 6

Moving the Insertion Point to the Beginning of the Document n You can use the Selection object’s HomeKey method to move the insertion point to a different area in the document n The HomeKey method, whose syntax is expression.HomeKey Unit:=unit, corresponds to the functionality of the Home key on your keyboard n 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 n To complete and test the UpdateMembership procedure, use the steps on pages 369 and 370 of the textbook 6

Completed UpdateMembership Procedure 6

Updated Membership Document 6

Access Lesson: The ADO Object Model n The ADO (ActiveX Data Objects) object model contains all of the objects needed to manage the records contained in one or more tables 6

The ADO Object Model n 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 n 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 6

Coding the PaymentUpdate Procedure n Begin by opening this database and viewing the Payments table n To open Professor Martinez’s database and view the Payments table, use the steps on pages 376 to 378 of the textbook 6

Pseudocode for the PaymentUpdate Procedure 6

Variables Used by the PaymentUpdate Procedure 6

Coding the PaymentUpdate Procedure 6 n To begin coding the PaymentUpdate procedure, use the steps on pages 379 and 380 of the textbook

Using the Recordset Object’s Open Method 6 n You use the Recordset object’s Open method to open a recordset n 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 6

Using the Recordset Object’s Open Method n The cursortype and locktype arguments in the syntax can be one of the constants n 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 n To continue coding the PaymentUpdate procedure, use the steps on page 382 of the textbook 6

Partially Completed PaymentUpdate Procedure 6

Using the Recordset Object’s Find Method n You can use the Recordset Object’s Find method to search for a value contained in a field in the recordset n The syntax of the Find method is recordset.Find Criteria:=criteria n To complete the PaymentUpdate procedure, use the steps on pages 384 and 385 of the textbook 6

Examples of Using the Find Method to Search the rstPays Recordset 6

Completed PaymentUpdate Procedure 6

Using the Recordset Object’s Find Method 6 n To test the PaymentUpdate procedure, use the steps on page 386 of the textbook