6 chapter six using visual basic 6.0 to create web-based database applications
Post on 20-Dec-2015
237 views
TRANSCRIPT
![Page 1: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/1.jpg)
6 ChapterSix
Using Visual Basic 6.0 to Create Web-Based
Database Applications
![Page 2: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/2.jpg)
6 Chapter Objectives
• Learn about the Visual Basic development environment
• Learn about the components of a Visual Basic database application
• Create a Visual Basic application using the ADO data control to display database data
![Page 3: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/3.jpg)
6 Chapter Objectives
• Create programmatic data controls to process data in a Visual Basic program
• Create a Visual Basic ActiveX document that is run from a Web page
![Page 4: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/4.jpg)
6 ActiveX Documents
• ActiveX documents– A program that users can download from a Web
site and install on their computers
Figure 6-1: Installing an ActiveX document
![Page 5: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/5.jpg)
6 Overview of Visual Basic
• Visual Basic– Can be used to create almost any kind of
Windows-based program
– An event-driven programming language• Program statements execute in response to user
actions or to system actions
![Page 6: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/6.jpg)
6 Components of a Visual Basic Program
• Project file– Specifies properties of the program and the names
of the individual component of the program
• Form– Main components of a VB project
– Composed of the visible interface that the user sees and interacts with, and the associated code that responds to user and system actions
![Page 7: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/7.jpg)
6 Components of a Visual Basic Program
• Standard module– Contains only code– Used to store declarations for variables that are used in
multiple forms
• Procedure– Manipulates variable values
• Function– Returns a single value based on parameters that are
passed to the function
![Page 8: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/8.jpg)
6 Components of a Visual Basic Program
• Controls are the visible items on a form
Figure 6-2: Form Controls
![Page 9: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/9.jpg)
6 Visual Basic Projects
• When VB is started, a new project is created, which corresponds to an individual user application
• When you create a new project, you can select the type of project it will be, which specifies how the project file is compiled
![Page 10: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/10.jpg)
6 Visual Basic Projects
Figure 6-3: Visual Basic project types
![Page 11: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/11.jpg)
6 The Visual Basic Development Environment
• Integrated development environment (IDE)– Environment for developing programs
Figure 6-4: VB IDE components
![Page 12: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/12.jpg)
6 The Visual Basic Development Environment
• Main IDE components include:– The toolbar provides quick access to menu bar
commands for opening
– The Object window shows the form and the position of the controls on the form
– The toolbox contains icons that are used to create form controls
![Page 13: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/13.jpg)
6 The Visual Basic Development Environment
• Main IDE components include (cont.)– The Project Explorer displays a hierarchical list of
the components of the current project
– The Properties window is used to assign and display the properties of the object that is currently selected in the Form window
• Docking– Allows the borders of windows to be attached, or
docked, to other windows
![Page 14: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/14.jpg)
6 Creating a Visual Basic Database Application
• Data control– Form control that is attached to a database table– Used to sequentially step through the record to
view the items
![Page 15: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/15.jpg)
6 Creating a Visual Basic Database Application
Figure 6-8: Clearwater Traders Inventory Maintenance application
![Page 16: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/16.jpg)
6 Modifying Form Properties
• The properties of a VB object specify the object’s appearance and behavior
• Name property– Determines how objects are internally
identified within the project– Must begin with a letter and can contain
characters, numbers, or underscores
![Page 17: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/17.jpg)
6 Modifying Form Properties
Table 6-1: VB object name prefixes
![Page 18: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/18.jpg)
6 Modifying Form Properties
• To follow accepted Windows application design guidelines, you should always modify the following form properties:– Border Style, which determines whether the user can
resize the form
– Caption,which is the form description that is displayed in the form’s title bar
– MaxButton, which allows the user to maximize the form so that it is displayed full-screen
![Page 19: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/19.jpg)
6 Modifying Form Properties
• To follow accepted Windows application design guidelines, you should always modify the following form properties (cont.):– MinButton, which allows the user to minimize
the form– StartUpPosition, which determines where the
form is displayed on the screen when the application is running
![Page 20: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/20.jpg)
6 Saving Visual Basic Projects
• A VB project is saved in a file with a .vbp extension
• Forms are saved in files with an .frm extension
• When you create a new project, it is very important to always save the project (.vbp) file and the form (.frm) file in the same folder in your file system
![Page 21: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/21.jpg)
6 Using Visual Basic with a Database
• ODBC driver– Low-level program that translates messages
from an application into the syntax expected by a specific database
– Each different type a database requires a different ODBC driver
– Always runs on the client workstation
![Page 22: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/22.jpg)
6 Using Visual Basic with a Database
• Programs written in program development languages and applications that access databases, need to communicate with ODBC drivers
• To simplify this communication, Microsoft has developed a variety of different data access technologies: Data Access Objects (DAO), Remote Data Objects (RDO), and ActiveX Data Objects (ADO)
![Page 23: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/23.jpg)
6 Using Visual Basic with a Database
• DAO– Available in most applications that support database
connectivity, but cannot support action queries that change content in some databases
• RDO– Full-featured, but only available in Microsoft’s high-end
enterprise-level programming environments
• ADO– Full-featured, is available in most Microsoft
environments, and supports most types of queries
![Page 24: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/24.jpg)
6 Using Visual Basic with a Database
Figure 6-12: Microsoft data access architecture using ODBC
![Page 25: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/25.jpg)
6 Using Visual Basic with a Database
Figure 6-13: Microsoft data access architecture using ADO and OLE DB
![Page 26: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/26.jpg)
6 Creating an ActiveX Data Control
• ActiveX data control– A control that is displayed on a form – Different from an ordinary form control
because it is associated with a recordset• A specific set of database records based on a SQL
query
![Page 27: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/27.jpg)
6 Creating an ActiveX Data Control
Figure 6-14: ActiveX data control
![Page 28: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/28.jpg)
6 Creating an ActiveX Data Control
• To create an ADO data control, you must add a type library to your project
• A type library is a library of code that has programs, such as additional controls, that you can add to VB IDE and then use in your project
![Page 29: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/29.jpg)
6 Using Program Code to Process Data
• With a programmatic data connection:– All of the commands to create the connections and
execute SQL commands are specified in a VB standard module
– User does not have to interact with a visible data control to perform database operations
![Page 30: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/30.jpg)
6 Using Program Code to Process Data
Figure 6-17: Creating a data connection programmatically
![Page 31: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/31.jpg)
6 Code in Visual Basic Programs
• A VB project consists of forms and standard code modules
• Every form and every code module has a section called the General Declarations section– Contains declarations for variables, and the code
for functions and procedures that are used in the form or code module
![Page 32: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/32.jpg)
6 Variables in Visual Basic Programs
• Visual Basic code has variables and data types just like other programming languages
• It is a good programming practice to always declare variables before using them
• VB does not require you to declare variables, but allows you to assign a value to a variable without declaring it first. This can lead to errors
![Page 33: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/33.jpg)
6 Variables in Visual Basic Programs
• Declaration keyword that is used to declare a variable depends on the desired scope of the variable
• Scope – Specifies how long the variable exists in memory
– Specifies what program components can assign and access the variable value
![Page 34: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/34.jpg)
6 Variables in Visual Basic Programs
• Variable declaration keywords are used as follows:– The Public keyword is used to declare global
variables– These are variables that are visible to all forms
and modules within a project
![Page 35: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/35.jpg)
6 Variables in Visual Basic Programs
• Variable declaration keywords are used as follows (cont.):– The Private keyword is used to declare form-
level and standard module-level variables
– These are variables that are visible only to procedures and functions written within the form or standard module where the variable is declared
![Page 36: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/36.jpg)
6 Variables in Visual Basic Programs
• Variable declaration keywords are used as follows (cont.):– The Dim keyword is used to declare local
variables– These are variables that are visible in the
function or procedure where they are declared
![Page 37: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/37.jpg)
6 Variables in Visual Basic Programs
• Variable declaration keywords are used as follows (cont.):– The Static keyword is used to declare local
variables whose values are only visible within the procedure where they are declared, but whose values still exist and can be accessed after the procedure is exited
![Page 38: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/38.jpg)
6 Variables in Visual Basic Programs
• The Variant data type can store any type of data
Table 6-2: Visual Basic data types
![Page 39: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/39.jpg)
6 Visual Basic Objects and Collections
• In object-oriented programming languages, an object is an item that has a specific structure and behavior
• Methods– Procedures that perform an operation on an object
• Collection– Contains a set of related objects
![Page 40: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/40.jpg)
6 Running Programs in the Visual Basic IDE
• Source code– The program code that you write
• Interpreted– Means that the code is translated to machine language
and executed one line at a time
• Compiled– Means that all of the code is translated into machine
language, and the machine-language version is then stored as an executable file
![Page 41: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/41.jpg)
6 Message Boxes
• A message box provides information to user regarding status of program or current operation
Figure 6-23: Message box
![Page 42: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/42.jpg)
6 Message Boxes
• A return value is an integer value that corresponds to the button the user clicks in the response to the message box
• A prompt is a text string that specifies the message displayed in the message box
Table 6-3: Message box return values
![Page 43: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/43.jpg)
6 Message Boxes
• Buttons – Defines the buttons that are displayed in the
message box– Commonly used values include:
• vbOKOnly
• vbOKCancel
• vbYesNo
• vbYesNoCancel
![Page 44: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/44.jpg)
6 Message Boxes
• Title is a text string that defines the text that is displayed in the message box title bar
Table 6-4: Predefined message box definitions
![Page 45: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/45.jpg)
6 Using a DataGrid Control
• To display database records on a Visual Basic form, you use a DataGrid– Always associated with an ADO control, which
specifies the database connection and the SQL query that returns the records that are displayed in the grid
![Page 46: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/46.jpg)
6 Using a DataGrid Control
Figure 6-29: Inventory form
![Page 47: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/47.jpg)
6 Displaying and Hiding Forms in a Project
• In Visual Basic, a form can be displayed as modal or modeless– Modeless
• User can interact with other project forms while the form is displayed
– Modal• User can interact with only the modal form, and
cannot interact with any other project forms until the modal form is unloaded
![Page 48: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/48.jpg)
6 Displaying Visual Basic Programs Using Web Pages
• Visual Basic projects can be created to make standard executable files
• Also can be created using different ActiveX options to make programs that can be installed and/or run by clicking a hyperlink on a Web page
![Page 49: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/49.jpg)
6 ActiveX Options Supported by Visual Basic
• Active documents– Have both a visual interface and code to process user
inputs and actions
• Active programs– Provide processing for other Web programs, but do not
have a visual interface component
• Active controls– Used to create custom controls that can be used in other
Web-based programming projects
![Page 50: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/50.jpg)
6 Creating an ActiveX Document
• User document– Container object in an ActiveX document – Similar to a form in the sense that it can contain
controls and code, and has events similar to those in a form
• A user document must be associated with, or sited on, an external application, which is called a container
![Page 51: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/51.jpg)
6 Creating an Installation Package for Your ActiveX Document
• Installation package - has the files needed to install an application on a user’s workstation
• Visual Basic provides a program called the Package and Development Wizard that leads developers through the steps needed to create an installation package
![Page 52: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/52.jpg)
6 Displaying an ActiveX Document using a Hyperlink
• When creating a Internet package using Package and Development Wizard, the Wizard creates an HTML file containing the command for the hyperlink that references the ActiveX document
Figure 6-34: Link to ActiveX document file in HTML file created by Package and Development Wizard
![Page 53: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/53.jpg)
6 ActiveX Documents and Security Considerations
• One approach to controlling and screening ActiveX programs is the use of verification certificates– These certify that software is from a
trustworthy source
• With verification certificates, users can be confident that the certified software will not harm their workstations
![Page 54: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/54.jpg)
6 Chapter Summary
• Visual Basic is a development language and used to create Windows-based applications
• A VB project can have forms and code modules• Visual Basic has an integrated development
environment (IDE) with multiple windows for displaying and modifying project components
• Visual Basic forms and controls have properties, which determine how the forms and controls look and function
![Page 55: 6 Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications](https://reader036.vdocuments.mx/reader036/viewer/2022062313/56649d415503460f94a1b6fa/html5/thumbnails/55.jpg)
6 Chapter Summary
• An Open Database Connectivity (ODBC) driver is a program that allows an application to interact with a database
• A DataGrid is used to display multiple database records in a matrix format
• You can create a VB project that is an ActiveX document, which has both visual components and code, and can be displayed as a Web page using the Microsoft Internet Explorer browser