Beruflich Dokumente
Kultur Dokumente
VISUAL BASIC
============================================================================
Section 01
Q1. What is the significance of the procedure and the
function in Visual Basic?
Ans: - Firstly we should know what is a function and a procedure.
Procedure and function are sub program’s that carry out a well
defined task. We can simplify program. Tasks by breaking the
prog. Into smaller logical components. This component is called
procedure and thus serves as the building blocks that let the
programmer to enhance and extend Visual Basic.
A procedure can receive one or more arguments and perform a
calculation. The sequence of statements can be placed with the
pair of sub and end sub statement and can be evoked by a name.
FUNCTION:-
-1- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
-2- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
3. Run the project
OLE has its own importance in VB. Through this tool we can make
the project/form more attractive and creative. Through this we can
call any object from any application. OLE is mainly used for
importing picture from any application to the VB form. OLE supports
the graphical features as well as text. We use OLE in VB to enhance
its working capacity/capability and to communicate data (text &
Graphics) from one window application to another OLE based.
We can add power point presentation to our form by selecting
power point presentation from the insert object dialog box.
OLE control
All the above mentioned items are the elements of OLE object insert
dialog box. And we all know about most of the elements and how
they work and why they are used. Then we can say that OLE works
as a bridge i.e. it minimizes the difference and gap between all
these elements and the user and thus after successful
implementation of these elements/objects in the visual Basic form
makes it more appealing thus it opens a no. Of windows to work on
it. It makes the visual basic broad in its application and thus it
creates new demands. OLE works like a soul in a body.
We can play music see movies/pictures, work with word
processors, spreadsheets, paint images and many more things
through visual basic with the help of OLE objects.
-3- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
It is easy to sue and apply in a form. It enhances the quality of
your work/project
And finally it also saves time.
-4- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
The database can be created in VB using the add-in prog.
The visual Data Manager. The visual Data Manager can be used
to create a Jet DataBase.
Data in these databases can be accessed in Visual Basic by
using the following options:-
1. Connect
2. Database name
3. Exclusive
4. Read only property
5. Record source
-5- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
bound and unbound control. A DAO is a collection of object
classes that model the structure of relation database system.
DBENGINE
WORKSPACE
DATABASE
TABLEDEF
FIELDS
INDEX AND
RECORDSET OBJECTS
RDO(Remote Data Objects):-
In order to access external data source like oracle, SQL server etc
we must create an ODBC data source. The ODBC databases are
created to help VB link the specified database in VB project.
The RDO is used to read and update data stored in Relational
DataBase Management System (RDBMS) that are external to VB and
MS Jet Data Engine. RDO has methods and properties that are better
suited to work with Remote database.
It works just like the Data control and DAO. It can be added
easily into the project by selecting project then components and
then Ms-ADO Data Control 6.0(OLEDB) from the list.
-6- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Common dialog
Data Bound Combo Box
Apex Data Bound Grid
Data Bound List Box
Microsoft Flex Grid
-7- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
5. The user control can be used in any application and the user may
resize the user control by using the user control_resize() event.
STEPS:-
Active X Document:-
-8- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
extension .VBD) and its corresponding server which can be an
Active X.Dll or Active X.Exe file. We cannot place an ActiveX.Dll or
ActiveX.exe file. we cannot place embedded objects or an OLE
container control on a user document.
---------------------------------------End Of Section
01-----------------------------------
-9- P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Section 02
If…Then:-
We can use either single line syntax or multiple line block syntax.
If…Then…Else:-
If<condition1> then
{statement block 1}
else if<condition2> then
{statement block2}
else
{
statement block n
}
end if
Example:-
Dim marks as integer
Marks=val(text1.text)
If marks>90 then
Text2.text=”good”
Else if
Marks>70 then
Text2.text=”satisfactory”
Else
- 10 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Text2.text=”labour hard”
End if
Syntax:- Do while<condition>
Statement
Loop
Example: dim k as integer
K=5
Do while k<10
Text1.text=k
K=k+1
- 11 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Loop
Syntax:- Do
Statement
Loop while<condition>
Example:-
- 12 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Loop structure- for each Next:- The loop structure is used to
repeat a group of statements each element in an array or
collection.
Dim ctrl as control
Dim ctr as integer
For each ctrl in form 1
If type of ctrl is text box then
Ctr=ctr+1
End if
Next
Msgbox(“Total no. of text boxes=”&ctr);
Q2. what are data files ? How do you create it and how do
you make use of it explain?
- 13 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Open <File Name> for append as #<File number>
- 14 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
- 15 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Open <File Name.txt> for Binary as #<File Number>
- 16 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
export the report to HTML or text files. The Data Report Designer
has
several functions:-
1. Drag and drop functionality for fields.
2. Toolbox controls
3. Print preview
4. Print reports
5. File export
6. Export templates
7. Asynchronous operation.
Property Setting
Connection student
Then click ok to close the dialog box and save the project. Once
the Data Environment Designer has been created, you can create
a data report. To do so select the data report designer in the
- 17 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
project explorer window and set the properties of the data report
object according to the table below.
Property Setting
Name rptstud
Caption student data report
On the properties window, click the data source and then click
data environment1
Properties Setting
Name cmdshow
Data report1.show
End sub
- 18 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Click the show Report Button to display the Report in print
preview mode.
SYSTEM FUNCTIONS:-
String functions:-
1) String functions:-
e.g.
Mystring=”hello”&spaces(10)&”world”
- 19 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Right : Returns a specified no. of characters from the right
side of the string
Syntax:- right (stringlength)
e.g
a=”hello Dev”
b=right(a,c)
‘returns “ev”
Syntax:- Rtrim(string)
Ltrim(string)
Trim(string)
e.g
mystring=” dev ”
a=Ltrim(mystring)
‘result “dev ”
e.g:
x-val(“29”)
‘returns x=29
Syntax:- now
Example:-
Today = now
‘assigns the current system data & time.
Syntax: time
- 20 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
Eg.
Today’s time= time
Connect
Database name
Exclusive
Read only property
Record source
- 21 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
DBENGINE
WORKSPACE
DATABASE
TABLEDEF
FIELDS
INDEX AND
RECORDSET OBJECTS
RDO(Remote Data Objects):-
In order to access external data source like oracle, SQL server etc
we must create an ODBC data source. The ODBC databases are
created to help VB link the specified database in VB project.
The RDO is used to read and update data stored in Relational
database Management System (RDBMS) that are external to VB and
MS Jet Data Engine. RDO has methods and properties that are better
suited to work with Remote database.
- 22 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
It works just like the Data control and DAO. It can be added
easily into the project by selecting project then components and
then Ms-ADO Data Control 6.0 (OLEDB) from the list.
4. To display the data from the table, add text fields on to the form.
To display the data from stdmast text boxes are added to the
form. You must now bind the indivudual date bound controls to
the data control, and then specify which field in the table each of
the control will display
- 23 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
At the design time, set the data source property of the bound
control to a data control. data field property can be set at
designed time or run time.
6) SAVE the project and run it (F5). Use the Arrow key of the data
control to scroll through the records of stdmast
Q5. How do you create Active x Documents? Explain?
On the file menu, click new project to open new project dialog
box. Double click on the active x document exe icon visual basic
automatically adds a user document designer to the project. If
the designer is not immediately visible right click over its default
name, user document 1, in the project explorer window, click new
object. When the designer appears its default name is visible in
the title bar.
In the properties window change the name of the user document
1 to first doc
In the project explorer window, double click the first doc icon to
bring it to the front
Place a command button on the form designer
- 24 -
P.T.O
B.Sc. IT 12-(01 & 02)
VISUAL BASIC
============================================================================
change the properties as
In order to view the first doc document, you must run the ACTIVE
X Doc project. It will load the container, Internet explorer in which
the document will be loaded.
-----------------------------------End Of Section
02-----------------------------------
THE END
- 25 -
P.T.O