Download presentation
Presentation is loading. Please wait.
Published byLauren Adams Modified over 9 years ago
1
Using Visual Basic 6.0 to Create Web-Based Database Applications
Chapter Six Using Visual Basic 6.0 to Create Web-Based Database Applications
2
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
3
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
4
Figure 6-1: Installing an ActiveX document
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
5
Overview of 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
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
7
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
8
Components of a Visual Basic Program
Controls are the visible items on a form Figure 6-2: Form Controls
9
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
10
Visual Basic Projects Figure 6-3: Visual Basic project types
11
The Visual Basic Development Environment
Integrated development environment (IDE) Environment for developing programs Figure 6-4: VB IDE components
12
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
13
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
14
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
15
Creating a Visual Basic Database Application
Figure 6-8: Clearwater Traders Inventory Maintenance application
16
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
17
Modifying Form Properties
Table 6-1: VB object name prefixes
18
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
19
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
20
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
21
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
22
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)
23
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
24
Using Visual Basic with a Database
Figure 6-12: Microsoft data access architecture using ODBC
25
Using Visual Basic with a Database
Figure 6-13: Microsoft data access architecture using ADO and OLE DB
26
Creating an 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
27
Creating an ActiveX Data Control
Figure 6-14: ActiveX data control
28
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
29
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
30
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 StudentAge = 22 StudentAge = StdentAge + 1 Option Explicit
31
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 Public, Private, Dim, Static
32
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
33
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
34
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
35
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
36
Variables in Visual Basic Programs
The Variant data type can store any type of data Table 6-2: Visual Basic data types
37
Visual Basic Objects and Collections
In object-oriented programming languages, an object is an item that has a specific structure and behavior (forms, controls) Methods (objects have associated methods) Procedures that perform an operation on an object Collection (forms collection contains all forms in a VB application) Contains a set of related objects
38
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
39
Message Boxes A message box provides information to user regarding status of program or current operation Figure 6-23: Message box
40
Using a DataGrid Control
Figure 6-29: Inventory form
41
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
42
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
43
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
44
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.