Understanding Visual Basic Fundamentals CHAPTER 13 Understanding Visual Basic Fundamentals.

Slides:



Advertisements
Similar presentations
Integrated Business Applications with Databases (D3) Jenny Pedler
Advertisements

AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
VBA Modules, Functions, Variables, and Constants
Using Visual Basic 6.0 to Create Web-Based Database Applications
CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Using Objects and Properties
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
1 Chapter 8 Object-Based Programming in VBA. 8 Chapter Objectives Declare and use object variables Create procedures that use built-in form methods Find.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
© McGraw-Hill Companies, Inc., McGraw-Hill/Irwin Extended Learning Module M Programming in Excel with VBA.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Using Visual Basic 6.0 to Create Web-Based Database Applications
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
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Working with Numeric Variables (Unit 6) Visual Basic for Applications.
Numeric Variables Visual Basic for Applications 6.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Committed to Shaping the Next Generation of IT Experts. Chapter 10 Customizing a Database.
Lab 01 Forms in excel Tahani ALdweesh Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
24/01/2011 harshana-fernando.blogspot.com 1 Introduction to Procedures Modules A module is a file that holds code or pieces of code in a Visual Basic application.
Chapter 9 Macros And Visual Basic For Applications.
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.
Types of Visual Basic Data Numeric Data Non Numeric Data.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
Visual Basic Programming I 56:150 Information System Design.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
Tutorial 101 Variable Arrays A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions.
Programming with Microsoft Visual Basic th Edition
Visual Basic CDA College Limassol Campus COM123 Visual Programming 1 Semester B Lecture:Pelekanou Olga Week 5: Useful Functions and Procedures.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Visual Basic Integrated Development Environment (IDE) 56:150 Information System Design.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Introduction to Programming Lecture 2
A variable is a name for a value stored in memory.
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
2. Understanding VB Variables
Microsoft Access 2003 Illustrated Complete
Microsoft Access Illustrated
Excel VBA Day 3 of 3 Tom Vorves.
Object-Oriented Programming: Classes and Objects
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Exploring Microsoft Office Access 2007
VISUAL BASIC.
Exploring Microsoft Excel
Chapter 3 Programming Fundamentals
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

Understanding Visual Basic Fundamentals CHAPTER 13 Understanding Visual Basic Fundamentals

1. Introduction Office Access 2003 uses the Visual Basic Editor common to all Office applications and to the Visual Basic programming product. The Visual Basic Editor provides color-coded syntax, an Object Browser, and other features. It also provides excellent tools for testing and confirming the proper execution of the code you write.

2. Modules Modules contain all Visual Basic code in your database. Access provides two ways to create a module:  Module object ◦ Form and Report Modules

2. Modules Module Objects  View the module objects in the Database window  Module objects are used to define procedures that you need to call from queries, forms or reports in your application.  Module objects can be called from anywhere in your application.

2. Modules Form and Report Modules ◦ Form and report module are used to respond events on forms or reports ◦ Form and report modules can be called only from within the scope Form or report.

2. Modules There are three main advantages when form and report module are used: −All the code you need to automate a form or a report resides with that form or report −Access loads the code for a form or a report only when the form or the report is opened and unloads it when the object is closed. −If you export a form or report, all the code in the form or report module is exported with it.

3. The Visual Basic Editor Window

Visual Basic Project Explorer window (Ctrl+R). Code window. Properties window (F4) Immediate window (Ctrl+G) Object list box ◦ When you’re editing a form or report class module, open this list on the left to select the form or the report Procedure list box: shows the available event procedures for the selected object

4. Visual Basic Debugging Tools Setting Breakpoints ◦ To set a breakpoint, click anywhere on the line of code where you want Visual Basic execution to halt. ◦ When a breakpoint is active, Access highlights the line of code where the breakpoint is established (thiết lập)

4. Visual Basic Debugging Tools Using the Immediate Window ◦ Type any valid Visual Basic command and press Enter to have it executed immediately (trực tiếp). ◦ To execute a procedure, type the procedure’s name followed by any parameter values. ◦ To evaluate any expression, type a question mark character followed by the expression.

5. Data Types Visual Basic supports data types for variables and constants that are similar to the data types you use to define fields in tables −Number −Currency −String −Date −Object

6. Variable and Constant Scope Public scope: Create variables or constants that can be used by any procedure in your database To declare a public variable, use the Public statement in the Declarations section of a standard module or a class module.

6. Variable and Constant Scope Private scope: Create variables or constants that apply only to the procedures in a module or only to a single procedure. To declare a public constant, use the Public keyword with a Const statement in the Declarations section of a standard module.

6. Variable and Constant Scope To declare a variable or a constant that all procedures in a module can reference, define that variable or constant in the Declarations section of the module. To declare a variable or a constant used only in a particular procedure, define that variable or constant as part of the procedure.

7. Declaring Constants and Variables Const Statement: to define a constant Syntax [Public | Private] Const {constantname [As datatype] = },... Example Public Const PI As Double =

7. Declaring Constants and Variables Dim Statement: to declare a variable Syntax Dim {[WithEvents] variablename [([ ],... )] [As [New] datatype]},... Examples Dim intMyInteger As Integer

7. Declaring Constants and Variables Private Statement: to declare variables that you can use in any procedure within the module. Syntax Private {[WithEvents] variablename [([ ],... )][As [New] datatype]},... Example Private lngMyNumber As Long

7. Declaring Constants and Variables Public Statement: to declare variables that you can use in any procedure anywhere in your database. Syntax Public {[WithEvents]variablename [([ ],... )] [As [New] datatype]},... Example Public lngMyNumber As Long

7. Declaring Constants and Variables Static Statement: to declare a variable used only in that procedure and that Visual Basic does not reinitialize while the module containing the procedure is open. Syntax Static {variablename [({ },...)] [As [New] datatype]},... Examples Static intMyInteger As Integer

8. Objects, Properties, and Methods The ActiveX Data Objects (ADO) Architecture Microsoft introduced a more generic set of data engine object models to provide references not only to objects stored by the JET DBEngine but also to data objects stored in other database products such as Microsoft SQL Server. These models are called the ActiveX Data Objects (ADO) architecture

8. Objects, Properties, and Methods Assigning an Object Variable—Set Statement Syntax Set objectvariablename =[New] objectreference Examples: create a variable reference to the current database, enter the following: Dim dbMyDB As DAO.Database Set dbMyDB = CurrentDb

8. Objects, Properties, and Methods Object Methods When you want to apply an action to an object in your databas, you apply a method of either the object or an eobject variable that you have assigned to point to the object

8. Objects, Properties, and Methods To open an ADO recordset, you must use the Open method of a new ADO Recordset object. The syntax to use the Open method of a Recordset object is as follows: − RecordSetObject.Open [source], [connection], − [cursortype], [locktype], [options]

9. Functions and Subroutines Function Statement Syntax Function functionname([ ]) [As datatype] [ ] [functionname = ] [Exit Function] [ ] [functionname = ] End Function

9. Functions and Subroutines Function MyFunction (intArg1 As Integer, strArg2 As String) As Double If strArg2 = "Square" Then MyFunction = intArg1 * intArg1 Else MyFunction = Sqr(intArg1) End If End Function

9. Functions and Subroutines Sub Statement: Syntax [Public | Private | Friend][Static] Sub subroutinename ([ ]) [ ] [Exit Sub] [ ] End Sub

10. Controlling the Flow of Statements Do…Loop Statement Syntax Do [{While | Until} ] [ ] [Exit Do] [ ] Loop

10. Controlling the Flow of Statements For…Next Statement Syntax For counter = first To last [Step stepamount] [ ] [Exit For] [ ] Next [counter]

10. Controlling the Flow of Statements For Each…Next Statement Syntax For Each item In group [ ] [Exit For] [ ] Next [item]

10. Controlling the Flow of Statements If…Then…Else Statement If Then [Else ]

10. Controlling the Flow of Statements Select Case Statement Syntax Select Case [Case [ ]]... [Case Else [ ]] End Select

11. Running Macro Actions and Menu Commands DoCmd Object: Use the methods of the DoCmd object to execute a macro action or menu command from within a Visual Basic procedure. Syntax DoCmd.actionmethod [actionargument],...

Executing a Menu Command Syntax [DoCmd.]RunCommand [actionargument],... Examples RunCommand acCmdSaveRecord