You are on page 1of 32

OOPS

USING VB
Defining OOPS :
Object- Oriented programming is a
method of analyzing, designing, and
writing applications using objects.
An object is a piece of code,
commonly referred to as a class, that
contains properties and methods.
Object can mimic business rules,
actions, or even physical objects.
Why should use OOPS :
Oops can compartmentalize the
functionality of a program into
discrete objects. It will help make
the program easies to design and
develop. It minimize the risk of one
piece of code interfering with
another piece of code. Oops works in
much the same way by providing
controls that determine what code is
used by other piece of code.
Methods of an Object :
Methods are the actions that an
object can perform. For example a
Window object can show itself, hide
itself, and even resize itself.

HRD Class
Name : Jhon
Position:Manager Properties
Request : Get record
for Throckmorton Van Method
Shlep
Encapsulation :
Encapsulation is a mechanism that
hides data and methods from the
programmer. It is used to shield the
programmer from the complexities of
the object. It prevents the
unauthorized person from viewing the
data.
Inheritance :
Inheritance is a form of software
reusability in which new classes are
created from existing classes by
absorbing their attributes and
behaviors and extending these with
capabilities the new classes require.
In other words new class is derived
from existing class is called
inheritance. Existing class is called
Base or Super class and new class is
called Derived or Sub class.
Polymorphism :
The ability to have methods with
the same name, but different content,
for related classes. The procedure to
use is determined at run time by the
class of the object. Polymorphism is
an ability to behave different in
different situations.
Dynamic Link Libraries (DLL)
DLLs are libraries routines, usually
written in C, C++, or Pascal that you can
link to and use at run-time.
All windows applications at their most
basic level interact with the computer
environment by using calls to dynamic link
libraries (DLL). The advantage to using DLLs
is that you can available routines without
having to duplicate the code in Basic. By
using DLL application may be faster, more
efficient, or more adaptable.
Windows API
The API Viewer is a browser that reads some
files that contain most of the function
declarations, variable types and constant
declarations that make up the windows API.
The viewer allows you to quickly search for
the function you want to call and supplies
you with the appropriate statements to
include in your application.
How to open Windows API:
Start Menu Programs Microsoft Visual Basic 6.0 Microsoft
Visual Basic 6.0 Tools API Text Viewer
API Text Viewer
Cont
The API Text Viewer used to obtain any
constants DLL routine may need because
1. To further confuse things, unlike VB
routine names, DLL calls are case-sensitive
we must pay attention to proper letter case
when accessing the API.
2. Always save your VB application before
testing any DLL calls. More good code has
gone down the tubes with GPFs- they are
very difficult to recover from.
Files :
A file is a collection of
information, it stores the information
permanently. The different types of
files are program files, textual
documents, sound files, videos,
picture files. The three types of file
access are
1. Sequential access files.
2. Random access files.
3. Binary files.
Cont
The 3 types files involves the
following 3 stages.
1. Opening the file.
2. Reading/Writing data
3. Closing the files.
Cont
Opening the file To build a
connection between the file and the
program and to reserve some memory
for storing the file data.
Reading and writing data To read
from or write to the file.
Closing the file To avoid
corruption of data, allow other
programs to access to release the
memory reserved for the file.
Sequential Access File :
Sequential access files store strings
of data as individual lines and it is designed
for use with plain text files.
These files are like cassettes, which
store data in a sequential manner. Data is
stored in the form of ANSI characters. You can
view a sequential file with any text editor.
When using sequential files, you must know the
order in which information was written to the
file to allow proper reading of the file.
Cont
Opening and Closing Files :
Opening a file perform one of the following
operations :
Input characters from a file.
Output characters to a file.
Append characters to a file.
Syntax :
Open file name For
[Input|Output|Append] As
#filenumber[Len=buffersize]
Cont
When a sequential file opens for Input,
the file must already exit: otherwise, error
occurs.When open a non-existent file for
Output or Append, the Open statement creates
the file first and then opens it.
FileNumber: Is any valid number in the range 1
to 511.
Len: It is optional argument specifies the
number of characters to buffer when copying
data between the file and program.
To close files use the following statement.
Close #filenumber
Random Access File :
Random access files store data as a
series of fixed size records. In random
access files the user can access
records directly by its number. These
files are like CDs. These files
organize data into records of same
length. The bytes in random files form
identical records, each containing one
or more fields.
Cont
Opening files for Random Access.
Open filename [For Random] As
filenumber Len=reclength
Reading a record.
Use the Get statement to copy
records into variables.
Get #FileNum,Position,VarName
Cont
Writing a file.
Use the Put statement to add or
replace records into files opened
for random access.
Put #FileNum, Position, VarName
Binary Access Files :
Binary access allows the user to
store data as a single string of binary
characters. It is similar to random
access, except that there are no
assumption made about data type or
record length. Binary access gives you
complete control over a file, because
the bytes in the file can represent
anything. It contain unformatted binary
data.
Cont
Opening a File for Binary Access.
Open filename For Binary As
#fileNumber
Database Connectivity
Visual Basic allows the user to
create database application in three
ways
Using controls DAO, ADO and ODBC.
Writing code.
Using wizards.
Data Access Object (DAO)
It provides a framework for using
code to create and manipulate database i.e.
it enables the user to move around in a
database from record to record and to
display and manipulate data from the record
in bound controls like Textbox, labels and
DataGrids etc. DAO allowed Visual Basic
developers to directly connect to Access
tables as well as other databases.
DAO Connection
Add Data control to the form.

Set the properties for the data


control. Properties are
1.Connect
2.Database Name
3.Recordset Type
4.RecordSource
ActiveX Data Object (ADO)
It is COM wrapper for the OLE-DB
interfaces. ADO allows developers to
access, through OLE-DB providers, a wide
variety of different data sources using a
common, easy to use object model. It is
very similar to the standard data control.
It provides high performance access to any
data source, including relational and non-
relational databases.
ADO Connection
Add ADO Data Control to Toolbox.
Right-Click the toolbox and select Components from
the pop-up menu.
In the Components dialog box, select Microsoft ADO
Data Control6.0 and click on OK. This will add the
control to the Toolbox.
Cont
Add ADO Data Control to form.

Right-Click on ADO control and select ADODC


properties. It displays property pages.
Cont
Set the connection string to click on Build
button. It displays Data Link Properties.
Cont
Click on Microsoft Jet 3.51 OLEDB provider
to use this driver to connect to the
database. Click on Next button.
Cont
Select the database name and click on OK
button. Now connection string property is
set.
Select RecordSource tab it displays
RecordSources.
Cont
Select the command type and Table or stored
procedure name.
Click on OK button to close the dialog box.
Set the Datasource and Datafield properties
to textbox, labels etc.
Run the project.

You might also like