VB 1-5 Unit - 240620 - 220336
VB 1-5 Unit - 240620 - 220336
VB 1-5 Unit - 240620 - 220336
UNIT 1
VB Programming Environment
To enter the VB environment, click the mouse on the VB icon which appears your
windows desktop. Enter the work space for a new project by selecting new/started or
selecting new project from the file menu.
2
Menu bar:
The second line is called the menu bar consists of file, edit, view format, project, help etc.…
Tool bar:
The third line is called the statement tool bar but it contains open , save,cut,copy, past,
delete, undo, start& end program.
3
Tool box:
Tool box contains icon that represent commonly used controls such as text boxes, label boxes,
frame check box etc.…can select a control frame the tools box& placed if in the currentform
design window.
The Toolbox is the selection menu for controls used in your application.
4
Properties window:
The Properties Window is used to establish initial property values for objects. The
drop-down box at the top of the window lists all objects in the current form. Two views are
available: Alphabetic and Categorized. Under this box are the available properties for the
currently selected object.
Project window:
Can display a form or module within the project container window. The Project Window
displays a list of all forms and modules making up your application. You can also obtain a view
of the Form or Code windows (window containing the actual Basic coding) from the Project
window.
As mentioned, the user interface is ‘drawn’ in the form window. There are two ways to
place controls on a form:
5
1. Double-click the tool in the toolbox and it is created with a default size on the form. You can
then move it or resize it.
2. Click the tool in the toolbox, then move the mouse pointer to the form window. The cursor
changes to a crosshair. Place the crosshair at the upper left corner of where you want the control
to be, press the left mouse button and hold it down while dragging the cursor toward the lower
right corner. When you release the mouse button, the control is drawn.
To move a control you have drawn, click the object in the form window and drag it to the
new location. Release the mouse button.
To resize a control, click the object so that it is select and sizing handles appear. Use
these handles to resize the object.
Codeeditor window:
If you double click on a control icon with in the form design window the code edited window
will open.
6
The Form Layout Window shows where (upon program execution) your form will be displayed
relative to your monitor’s screen.
Immediate window: -
Developing an application
In these topic how use can develop an application or program.
Design
Create
Write
Break
Run
Design:
What the program is supposed to do.(Used to build application.)
Create:
User interface using visual basic program development tools. This generally involved two related
activities.
a) Draw the controls with their respective form.
b) Define the properties of each control.
Write:
The visual basic instructions to carried out the actions resulting from the various program
events.These can generally involves writing a group of commands called an event procedure.
Break:
Application halted and debugger is available.
Run:
Used to run the application. The program to verify that it executes correctly.
Modules
Code in vb stored in the form of modules.
3 kinds of modules are:
Form modules
Standard modules
Class modules
Large projects are much more manageable if they broke up in to modul. Each of which
contains portions of the cord comprising the entire project. Visual basic support several
types of modules,
Each of which is stored as a separated file. Form modules are stored as a file identified by
the extension whenever added a new form to a project and then said the form a separated
9
form module is created module. A project may also include a standard module. A
standard module contains declaration and procedures.
Data Types
Variables
We’re now ready to attach code to our application. As objects are added to the form,
Visual Basic automatically builds a framework of all event procedures. We simply add
code to the event procedures we want our application to respond to. But before we do
this, we need to discuss variables.
Variables are used by Visual Basic to hold information needed by your application.
Rules used in naming variables:
Variable Declaration:
10
If variables are not implicitly or explicitly typed, they are assigned the variant type by
default. The variant data type is a special type used by Visual Basic that can contain
numeric, string, or date data.
To implicitly type a variable, use the corresponding suffix shown above in the data type
table. For example,
Text Value$ = "This is a string"
Creates a string variable, while
Amount% = 300
Creates an integer variable.
There are many advantages to explicitly typing variables. Primarily, we ensure all
computations are properly done, mistyped variable names are easily spotted, and Visual
Basic will take care of insuring consistency in upper- and lower-case letters used in
variable names. Because of these advantages, and because it is good programming
practice, we will explicitly type all variables.
To explicitly type a variable, you must first determine its scope. There are four levels of
scope:
⇒ Procedure level ⇒ Procedure level, static ⇒ Form and module level ⇒ Global
level
Within a procedure, variables are declared using the Dim statement:
Dim MyInt as Integer Dim My Double as Double Dim My String, Your String
as String. Procedure level variables declared in this manner do not retain their
value once a procedure terminates.
To make a procedure level variable retain its value upon exiting the procedure, replace
the Dim keyword with Static:
Static MyInt as Integer Static My Double as Double
VB Statements…
End Sub
1. Event procedure
2. Sub procedure
3. Function procedure
Event procedure: -
Event procedure is a procedure associated with the event of an object and are named
in a way that indicates both event and object clearly. It is accessed by specific action. Such as
clicking on an object name and the activating event collectively makeup the even procedures.
E.g.:
And end sub in between instruction will also called as object or control.
Sub procedures: -
Sub Procedures perform actions but do not return a value to the calling code.
Event-handling procedures are sub procedures that execute in response to an event raised
by user action or by an occurrence in a program.
Function Procedures return a value to the calling code.
Event Procedure:
E.g.: Private sub command one click. Private sub from load one the object and action
have been selected,
Syntax:
Sub procedure name(arguments)
-------------------------------------
Statements
-------------------------------------
End sub
It subs procedure can be accessed from elsewhere within the model by call the
statements.
[The call statement is return as [call procedure name (arguments)]
12
Coding: -
Function procedure:
A Function procedure is a series of Visual Basic statements enclosed by the Function and
End Function statements. The Function procedure performs a task and then returns control to the
calling code. When it returns control, it also returns a value to the calling code.
Each time the procedure is called, its statements run, starting with the first executable
statement after the Function statement and ending with the first End Function, Exit Function, or
Return statement encountered.
Control Structures
Control Statements are used to control the flow of program's execution. Visual Basic supports
control structures such as if... Then, if...Then ...Else, Select...Case, and Loop structures such
as Do While...Loop, While...Wend, For...Next etc method.
The If...Then...Else selection structure allows the programmer to specify that a different action
is to be performed when the condition is True than when the condition is False.
Looping Statements
A repetition structure allows the programmer to that an action is to be repeated until given
condition is true.
Do While... Loop Statement
The Do While...Loop is used to execute statements until a certain condition is met. The
following Do Loop counts from 1 to 100.
number = 1
While number <=100
number = number + 1
Wend
The Do...Loop While statement first executes the statements and then test the condition after
each execution. The following program block illustrates the structure:
Dim number As Long
number = 0
Do
number = number + 1
Loop While number < 201
Do Until...Loop Statement
The For...Next Loop is another way to make loops in Visual Basic. For...Next repetition
structure handles all the details of counter-controlled repetition. The following loop counts
the numbers from 1 to 100:
Dim x As Integer
For x = 1 To 50
Print x
Next
Arrays
Up to now, we've only worked with regular variables, each having its own unique name.
Visual Basic has powerful facilities for handling multi-dimensional variables, or arrays.
For now, we'll only use single, fixed-dimension arrays.
Arrays are declared in a manner identical to that used for regular variables. For example,
to declare an integer array named 'Items', with dimension 9, at the procedure level, we
use:
Dim Items (9) as Integer
If we want the array variables to retain their value upon leaving a procedure, we use the
keyword Static:
Static Items (9) as Integer
At the form or module level, in the general declarations area of the Code window, use:
Dim Items (9) as Integer
And, at the module level, for a global declaration, use:
Global Items (9) as Integer
The index on an array variable begins at 0 and ends at the dimensioned value. For
example, the Items array in the above examples has ten elements, ranging from Items (0)
to Items (9). You use array variables just like any other variable - just remember to
include its name and its index. For example, to set Item ((5) equal to 7, you simply write:
Item (5) = 7
Combo Box
Check box
Option button
Shape control
DrivelListBox
Image Control
Text box
The text box is the standard control for accepting input from the user as well as to display the
output.It can handle string (text) and numeric data but not images or pictures.
Private Sub Command1_click ()
‘To add the values in TextBox1
Ana Textbox2
Sum =Val (Text1.Text) +Val (Text2.Text)
‘To display the answer on label 1
Label1.caption = Sum
End Sub
Label Box:
The label is a very useful control for visual basic, as it not only used to provide instructions and
guides to the users, it can be also be used to display out puts. One of its most important
properties is caption. Using syntax label. Caption, it can display text and numeric data.
Command Button: -
The command button is one of the most important controls as it is used to execute commands. It
displaysan illusion that the button is pressed when the userclicks on it.
Picture Box: -
The picture box is one of the most important control that is used to handle graphics. Picture click
in properties window and select the picture from the selector folder.
17
List box: -
The function of the list box is to present a list of items where the user can click and select the
items from the list. In order add item method .for example-add no of items list box following
statements,
Combo Box:-
The function combo Box is also to present a list of item where the user can click and select the
items from the list. In order to add items to the list, use the Add item method.
Check box:-
The check Box controls lets the user selects or unselects an option. When the check box is
checked, its value is set to 1 and when it is uncheck, the value is set to zero. Include the
statements check check1.value =0 to mark the check box and check1.value =0tounmark the
check box, as well as use them toinitiatesertion actions.
18
Option button:-
The option button control also lets the user selects one of the choices.Theothe option button is
unselected.it will be one option button can be selected at one time.
Custom Controls:-
A custom control is an extension to the standard Visual Basic toolbox. You use custom
controls just as you would any other control.
The masked edit control is used to prompt users for data input using a mask pattern. The
mask allows you to specify exactly the desired input format. With a mask, the control
acts like a standard text box. This control is loaded by selecting the Microsoft Masked
Edit Control from the Components dialog box.
Chart Control:-
The chart control is an amazing tool. In fact, it’s like a complete program in itself. It allows
you to design all types of graphs interactively on your form. Then, at run-time, draw graphs,
print them, copy them, and change their styles. The control is loaded by selecting Microsoft
Multimedia Control:-
The multimedia control allows you to manage Media Control Interface (MCI) devices.
These devices include: sound boards, MIDI sequencers, CD-ROM drives, audio players,
videodisc players, and videotape recorders and players. This control is loaded by
selecting the Microsoft Multimedia Control from the Components dialog box.
19
A control array can be created by placing a control within the form design
window. And assainging a value of zero of its index property.
They copy and passed control.Resulting in a new control with the same name (but
an index value of one.)
Suppose we wish to create a control array. Whose elements are
check boxes and label boxes, left as being with an empty form and then one check
box is normal manner.
Review Questions
1. Discuss about variables in vb.
2. How procedures and functions are implemented?
3. What are the various control structures supported by vb.
4. Differentiate event procedure and property procedure.
5. What are different categories of controls in vb.
6. Define the salient features of control array.
21
UNIT-2
Menus
Visual basic application can be adding menu is an easy way or use as to access them.
Themenu bar appearbelow the title bar and it may contain one or more menu title.
When a menu title is clicked it displays it set of menu item under that titles
Eg:edit, save,open.
Using the menu editor
A menu editor can be used to add new commands to the existing menu creating new menus,
menu boxes, change or deleting existing menu and menu bars.
To display menu editor, menu editor command is choose from the tool menu or the menu
editor button is clicked in the tool bar.
Mouse events
VB application respond to various mouse events are mouse down, mouse up and mouse
move.
Mouse down occurs when the user process any mouse button.
Mouse up occurs when the user release any mouse button.
Mouse move occurs when ever the mouse pointer is moved to a new point on the screen.
This events used the arguments button , shift button , X,Y and they contain information about
the mouse condition when the button is clicked.
Dialog box:
Dialog boxes are used to display information and the user about the data.
The user about the data need to continue an application 3 ways to adding dialog boxes to an
application.
Predefined dialog box:
The input box function display a model dialog box that ask the user to enter some data.
A dialog box contain a message an ok button and a cancel button.
The user can type the text box and the close dialog box by clicking ok.
Rich text box function:
The rich text box and control allows user to enter and edit text.
While also providing more advanced formatting features than the normal text box control.
Using properties text bold, italic, change its colour and create super script and subscript.
We can also use adjust a paragraph formatting by selecting both left and right indents
Eg-standard EXEprojectcomponentsMS.rich text box ctrl 6.0 select the box and then apply
ok.
MDI FORM
PROPERTY
Right click on the MDI form from the project explores windows add 3 or more forms.
In property window set the child forms are true. in MDI form change the caption as parent.
Review Questions
1. Write short note on mouse events.
2. What is meant by an event? How are they handled?
3. Describe dialog box control in vb.
4. Explain the usage of multiple document interface.
5. Explain about flexgrid control.
24
UNIT III
ODBC and Data Access Objects:
ODBC
An ODBC driver user the open data base connectivity interface by Microsoft that allows
application to access data in data base managementsystem, using sql as a standard for
accessing the data:
ODBC was originally developed by Microsoft and samba technology is during 1990.
It is computing, open data baseconnectivity (ODBC)is a standard application
programming interface (API)accessing databaseManagement system (DBMS).
ODBC accomplishes DBMS independence by using an ODBC driver as a transition layer
between the application and the ODBC.
Users:
“Working with Access Collections and Objects,” you’re already prepared for DAO and
any other object model that might come your way.
All the concepts presented about properties, methods, and collections work the same way.
The only changes are the names of the objects and the types of members they contain.
“Driving Office Applications with Automation,” focuses on programming Excel, Word,
and other VBA-supported applications through Automation.
Again, using these object models with DAO just requires that you understand the
different types of objects and their spec- civic properties and methods; you don’t need to
learn any new basic concepts.
DAO is one of Microsoft’s models for accessing databases. This object model coexists
with the Access programming model.
However, the DAO feature is also a separate component available in all Microsoft
applications that support VBA.
Therefore, you can use what you learn in this appendix for programming in Office 2002
as well as in Visual Basic 4 and greater.
DAO provides a consistent object-oriented interface for performing all database-related
functions.
Although this might sound intimidating, DAO is not only extremely powerful, but is also
very easy to use. Some of its features are as follows:
The capability to create and edit databases, tables, queries, indexes, fields, referential
integrity rules, and security.
The capability to access data by using SQL. Methods are also available for navigating
and searching through the data in tables and data resulting from queries.
Support for beginning, committing, and canceling transactions. Transactions, which can
be nested, are useful for performing bulk operations on the database as a single action.
The capability to create custom properties on any DAO.
The capability to repair and compact databases from the programming language.
Support for attaching remote tables to your database, as well as for managing the
connection.
When examining DAO, it helps to analyze the composition of your database. Databases in
Access are composed of the following pieces:
26
Tables Reports
Queries Code modules and macros
Forms Security information
Data Access Pages Relationships
All these elements make up your database. DAO provides an interface to obtain a
tremendous amount of information about each element.
You can obtain information about a table’s definition, all its fields, indexes, and
relationships.
You can quickly and easily add or delete moretables, queries, or relationships.
You can even add to these objects custom properties that are saved with the database.
All this power is easily accessible through that consistent program- Ming paradigm
known as DAO.
Because DAO consists of such a large number of objects, it helps to see a road map of
how all these objects relate.
As with most object models, DAO has a distinct object hierarchy. In Access you start
with the Application object, whereas in DAO you start with DBEngine.
In this section, you learn how to maneuver through the object hierarchy by manipulating
each object.
Figure shows the diagram representing the DAO object hierarchy. This diagram
demonstrates the hierarchy or tree of objects that DAO exposes. From Figure, you can
see the numerous available objects and the path you must follow to reach them.
27
Introduction:
Visual basic provides variety of options when it comes to accessing the data stored in the
database.Find all options bellow.
Data access objects(DAO):-It communicates with the Microsoft access and other
ODBC compliant data sources through the JET engine.
ODBC Direct:-It allows accessing ODBC data sources through the RDO (Remote
Data Objects) and DAO objects bypassing the JET database engine.
Data control: - It binds data- aware controls to Microsoft access or other ODBC data
sources.
Remote Data Objects(RDO):-It provides aframe work for using code to create and
manipulate components of a remote ODBC database system.
It provides aframe work for using code to create and manipulate components of a
remote ODBC database system.
28
Remote Data Objectsis an obsolete data access application programming interfaceprimarily used
in Microsoft Visual Basic Applications on windows 95 and later operating systems. This
includes database connection,queries,stored procedures, result manipulations,and change
commits.RDO (Remote Data Object) Application Program interface (API) from Microsoft that
lets programmers writing windows application get access and from both Microsoft and other
database provides.It provides aframe work for using code to create and manipulate components
of a remote ODBC database system.
The ActiveX EXE that we are creating contains the following features.
It has single class Time.
A form that is displayed only When ActiveX EXE is invoked as a standalone application.
A form of Active EXE is used to display running digital clock using time class of the
ActiveX EXE.
The clientapplication as usual users an object of time class to invoked methods such as
GetTime,SetTime.
The startup object ofActiveX EXE is sub main which is procedures in code module.
Main procedures determines whether form is server is to be displayed or not depending upon
whether server is invoked as standalone application or invoked by client application.
ActiveX DLL
An ActiveX DLL is a DLL that supports OLE Component object model (COM).
A dynamic link library (DDL) is a file that contains compiled code……
In VB, you create a DLL by selecting ActiveX DLL for the New Project dialogue box.
The new project will be containing single class module, which illustrates how VB DLLs
work.
DDL. Stands for “Dynamic Link Library”.
A DLL (.dll)file contains a library of function and other information that can be accessed
by a window program.
When program launched, links to ne the necessary.
In the professional and enterprise edition of visual basic, you can use
class modules to create ActiveX components and compile them as either ActiveX DLL or
ActiveX EXEs.The choice with are faced with,effectively, is whether you require an in process
or an out-of process component.
In-Process Components:
It become part of the process space of the application that calls the DLL.
Out-0f-Process Components: -
When you create an ActiveX EXE, you are creating an out of -process components.
An ActiveX EXE runs as a separate process with its own threads. This is ideal for cases
in which multiple applications.(or multiple clients)
Are likely to require the functionality offered by the classes included in the ActiveX
EXE.
These are the creating ActiveX EXE Components and Creating an ActiveX DLL
Components.
Review Questions
UNIT IV
OBJECT LINKING AND EMBEDDING
Introduction
An important feature of the Microsoft windows operating system its ability for sharing
information among applications.
OLE is a means of communication which gives any application the power to directly use
and manipulate other windows application
OLE Fundamentals
DDE is an acronym for Dynamic Data Exchange.it is the basic foundation for inter
process communication between applications.
There is a functional similarities between OLE and DDE and there are few differences.
OLE actually transfers control to the original applications.
OLE is a technology that enables the programmer of a windows based application to
create an application that can display data from many different applications.
Object and classes
31
OLE automation
Some application provide object that support OLE automation.
Some object that support OLE automation that also support linking and embedding.
Container application
Linked objects
Data associated with a link object is stored by the application that supplied the object. this
application store only link references that displays a snap shot of the source data.
Embedded object
When an embedded object is created. all the data associated with that object is contained in
the object.
When an object is inserted into the OLE control at design time, the class, Source Doc
and source item properties that identify the application that supplies the object, the
32
source file name and any specific file that is linked from within that file are
automatically set.
Creating object at run time
To create a linked or embedded object at run time, various method and properties are
used in the code .
We can create a linked object at runtime using the source Doc property and create
linked method.
The following code fragment creates a linked object at run time
OLE1.CreateLink “C:\OLE.x1s”
Moving or sizing the OLE Container
The OLE container control has an Object move event, which is triggered when the
object associated with the control is moved or resized.
OLEDrag Method
33
OLEDragMode Property
Determine if the object act as an OLE drag source,and if the OLEDrag operation is
ndone manually or automatically
The allowable property values are:
vbOLEDragManual-0 – This is the default value.It is used when the user’s own
OLE drag handlers are wused in the application.
vbOLEDragAutomatic-1 – Used when application has to handle the drag and
drop operation.
OLEDropMode Property
OLEDropAllowed Property
Determine whether the OLE drop operations are allowed or not
If set to true, allows OLE drop operation on the container, otherwise operation are
prohibited.
OLEDragDrop() event
identify the button on the mouse that was clicked during OLE drag operation. The x
and y indicates the current position of the mouse pointer.
VB6 provided three native toolbox controls for working with the file system:
the DriveListBox, DirectoryListBox, and FileListBox.
These controls could be used independently, or in concert with one another to navigate
the file system.
We can select the desired file by selecting a drive from the DriveListBox, a directory
from the DirectoryListBox and a file from the FileListBox.
Accessing Files
Sequential access files are accessed line by line and are ideal for applications that
manipulate text files.
Sequential access file is opened in one of the three ways- output, Append, or Input.
Binary access files are accessed byte by once a file is opened for binary access we can
read from and write to any byte location in the file.
The ability to access any desired by in the file makes it the most flexible one.
Before accessing a file in binary mode the file should be opened first for binary access
Review Questions
35
UNIT V
Additional controls in VB
SSTab control
The SSTab control provides an easy way of presenting several dialogs or screens of
information on a single form.
Only one tab is active in the control at a time.
Working with SSTab
SSTab1.TabPerRow=4
The tab orientation property allows you to locate the tabs of your tabbed dialog box on
either of the four sides:
SSTab1.TabOrientaion=SSTabOrientation Left(or)
SSTab1.TabOrientaion=SSTabOrientation Right
SSTab1.TabOrientaion=SSTabOrientation Top (or)
SSTab1.TabOrientaion=SSTabOrientation Bottom (or)
The image list control acts like a repository of images for the other control.
An image list control contains a collection of images that can be used by the other
windows common controls.
The control uses bitmap(.bmp), cursor(.cur), icon(.ico), JPEG(.jpeg),or GIF(.gif) files in a
collection of list image object.
You can add and delete images at design time or runtime.
Working with the image list control
Start a new project. You can add the image List control.
From the list of component select Microsoft window common control6.0.
The image list control and the other controls will get added to the toolbox.
Adding images to the image list
To add an image to a control at design time use the image list control property pages
dialog box.
To add list image at design time
Right click the image list control and click properties to bring up the property pages.
Click the images tab to display the image list controls property pages.
Click insert picture to display the selected picture dialog box.
Click on the key box and enter a string that will uniquely identify that image.
We can add and remove images to control at design
Time or run time.
TabStrip control
The function of a Tab strip control is very similar to the SSTab.
It is used for a tabbed dialog box to allow user to set various attributes.
The control consist of one or more tab object in a tabs collection.
You can affect the tab object appearance by setting properties at runtime and design time.
Creating tabs at design time and runtime
1. Right click the tab strip control and click the properties to display the properties pages
dialog box.
2. Click the tab to display the tab page and make the display.You can add a tab at runtime
with code like this:
TabStrip1.Tabs.Add,”find”,”Find”,”Fbook”
The user can sort, merge and format tables containing string and pictures.
MS Flex grid control allow read only data.
We can allow the user to enter data in the Flex Grid using a text box.
The user can resize the cell width or height in design time or runtime.
Why ADO
Active x data object is the new data access technology offered by Microsoft.
ADO mean to replace DAO, RDO, and ODBC.
We can access any type of data and store it locally in a new type of database and tackle
with various type of data
application
ADO
database
ADO enabled your client application to access and manipulate data in a database server
through any of the OLE DB providers.
ADO is primary benefits are ease of use , high speed, low memory overhead and a small
disk footprint.
The ADO acts like a intermediate between the application and OLE DB.
connection
error
command
parameter
Recordset
39
field
Connection
The ADO Error object contains details about data access errors that have been generated
during a single operation.
Command
Once a connection has beenestablished with the data source the data has to be extracted
.this is done using the command object.
Parameter
parameter are arguments to a command that alter the result of the execution of the
command
Record set
The command object when executed will return a set of rows from one or more table.
This set of record is called record set.
Field
A row of a record set has one or more field. To change the data in the data source you
have to modify the value of the field.
Establishing a reference
Open a new project. To use ADO in your project,you have to make a reference to it.
This is done just as we made the reference to DAO
Click on the project, and from the menu select references.
From the list displayed in the references dialog boxes select the Microsoft Active X Data
objects 2.0.now you can use ADO in your project.
In order to achieve our object of accessing a data source, extracting a set records from it
and manipulating or editing the record set and finally updating the data source.
The data source we have to the following steps:
Make a connection to a data source
Create a command to specify the records to be extracted.
40
Crystal Report
Crystal Report Writer is a report generation tool.
It is used to generate simple to slightly complex reports. However, with Visual Basic 6.0
onwards you also get Data Reports. So you can generate a report either with CRW
(Crystal Report Writer) or with Data Report.
CRW is not a product from Microsoft. It is from Segate Software.
A report created using Crystal Reports is accessed from a Visual Basic project using an
ActiveX Control - Crystal Report Control.
The best part of Crystal Reports is its user friendliness. Even an end-user will be able to
generate a report in a few minutes. It is also powerful enough to enable application
developer to generate moderate to complex reports.
Starting CRW(Crystal Report Writer) :First make sure CRW is installed in your machine.
If it is not installed, install it from Visual Studio CDs. Note that by default CRW is not
installed. So install it from Common\tools\Visual Basic\ crysrept directory of the Visual
studio CD.If it is installed, then you start CRW as follows:
1. Click on Start button
2. Select Programs-> Microsoft Visual Studio 6.0 -> Crystal Reports. In which group crystal
reports is placed depends upon the group selection at the time of installation.
3. If you are prompted to enter registration details, cancel it or register and then click on Ok.
4. The initial screen of Crystal Reports will be displayed.
Crystal Reports for enterprise provides an interface that enables you to quickly and easily
create, format, and publish effective reports.The menu bar provides full range of features
available in Crystal Reports for Enterprise as shown in the following image.
41
The standard toolbar as shown in the following image allows you to access common Report
functions such as: Open an existing report, create a new report, save a report, print a report,
cut, paste, export and undo.
42
The Insert tab allows you to insert objects into you report, such as inserting a text, line, box,
groups, sections, pictures, calculations and/or charts, as shown in the following image.
The Format tab as shown in the following image, allows you to use functions for formatting
the selected field such as: changing the font size or font color, background color, alignment
of text to center, left, right, etc.It also allows you to apply conditional formatting, such as
highlighting values above or below a specific threshold value in the report.
When you click on conditional formatting option at top right corner, the formatting box open.
In this box, you define the condition under which you want conditional formatting to appear.
In setting area, specify the formatting to appear when condition is met, like changing font
style or color of text.The Data tab as shown in the following figure, enables you to work with
data-editing queries, creating groups and sorts, applying filters to limit data in the report
and creating formulas to add custom calculations to reports.
When you click on Query filter option or on Edit data sources, as shown in the following image,
a query panel opens. In the Query panel, you can select objects that you want to see in the report.
In the filter option, you can apply filters to restrict the data returned by the report.
43
When you click on Formula button, as shown in the following image, the Formula workshop
opens. This allow you to use custom calculations in the report. You can apply formulas by typing
or by clicking on objects, functions and operators in the data explorer.
44
The main working area in Crystal Reports is known as Report Design Canvas and is divided
into structure tab and page tab. Crystal Report is divided into five different parts by default and
additional sections are added if you apply grouping to the report.
45
Using the Structure tab, as shown in the above image, you can create the overall structure by
placing items in various sections of the report. You can also apply any required sorting,
grouping, etc. Here, you work with placeholders for data and not data itself.
The Page tab, as shown in the following image, displays the report data on the basis of the
structure you created in the structure tab. Here, you can evaluate formatting and layout of the
report design for distribution.
Data Report
Helps you design a report that displays fields and records from the underlying table or
query.
A report is an effective way to present data in a printed format. You can display the
information the way you want to see it
You create the report using graphical object called Data report designer controls. Data
report designer controls. Include: a data-bound Textbox control, a function control which
displays calculated figures, and Image control for inserting graphics, labels that display
captions, and a line and a shape control that graphically organizes the data.
The Data Report generates reports using records from database. To use it.
1. Configure a data source, such as the Microsoft data environment, to access a
database.
2. set the Data member property of the data report object to a data member.
3. set the data member property of the Data Report.
4. Right click the designer and click retrieve structure,
5. Add appropriate controls to the appropriate sections.
6. Set the data member and Data field properties for each control.
46
7. At run time, use the show method to display the data report.
Use the data report object to programmatically change the appearance and behaviour of
the data report by changing the layout of each section object.
The data report designer also features the ability to export reports using the export report
method. This method allows you specify an export format object, from the export formats
collection, to use as a template \for the report.
1. Data Report Object – Similar to a Visual Basic form, the Data Report object has a
visual designer. It is used to create the layout of a report.
2. Section object – The Data report designer contains sections which helps to configure the
report more elegantly. The sections of the Data report designer is explained in the next
section.
3. Data report controls – special controls that only work on the data report designer are
included with it. These controls are found in the Visual Basic toolbox, but they are placed
on a separate tab named “Data Report’
4. Report Designer – User the report Designer to create and modify reports. When the
report designer window is active, Visual Basic display report controls toolbar.
Data report designer features – the data report designer has several features:
1. Drag and drop functionality for fields - When fields are dragged from the
Microsoft data environment designer to the data report designer, Visual Basic
automatically create a text box control on the data report and sets the Data
member and Data Field Properties of the dropped field. A command object can
also be dragged from the Data environment designer to the data report designer.
In that case, for each of the fields contained by the command object, a text box
control with be created on the date report; the Data member and Data field
property for each text box will be set to the appropriate values
47
2. Toolbox controls – The data report designer features its own set of controls.
When a Data report designer is added to a project, the controls are automatically
crated on a new toolbox tab named Data report. Most of the controls are
functionally identical to Visual Basic intrinsic controls, and include a label, shape,
image, textbox, and line control. The sixth control, the function
control,automatically generates one of four kinds of information: sum, average,
minimum, of maximum.
3. Print Report – When a report is generated, it can be printed by clicking the
printer icon on the toolbar.
4. File export – in addition to creating printable reports, it can be exported to text
files, by clicking the export icon and specifying text file name.
Section of the Data Report Designer- The Data report designer contains the following
sections:
1. Report Header – Contains the text that appears at the very beginning of a report,
such as the report title, author, or database name.
2. Page Header – Contains information that goes at the top of every page, such as
the report’s title.
3. Group Header/Footer – contains a “repeating” section of the data report. Each
group header is matched with group footer. The header and footer pair are
associated with a single command object in the data environment designer.
4. Details- Contains the innermost “repeating” part (the records) of the report. The
details section is associate with the lowest level command object in a data
environment hierarchy.
5. Page Footer – Contains the information that goes at the bottom of every page,
such as the page number.
6. Report Footer – Contains the text that appears at the very end of the report, such
as summary information, or an address of contact name.
Printing a Data Report - Printing a data report can be accomplished in one of two ways.
The user can click the print button that appears on the data report in print preview mode
(using the show method), or you can programmatically enable printing using the print
report method.
Choosing to display a print dialog box - When printing a report programmatically, you
have two choices:
Print by displaying the print dialog box- Add a command button to a form.In the
button’s click event, place the following code:
Printing without displaying the dialog box- Add a command button to a fromIn
the button’s click event, place the following code:
48
Print Report Method - At run time, prints the data report created with the data report
designer.Syntax
Object. Print report (Show Dialog, Range, and Page From, Page To)
Review Questions