Professional Documents
Culture Documents
VISUAL BASIC
1. WHAT IS PROGRAMMING?
2. WHAT IS TRASLATOR?
ANS:-
TRANSLATOR
A. COMPILER:-
B.INTERPRETER:-
HIGH LEVEL TRANSLATE LINE BY LINE LOW LEVEL LANGUAGE
LANGUAGE (HLL) (LLL)/MACHINE LEVEL
LANGUAGE (MLL)
2
C.ASSEMBLER:-
ASSEMBLY LEVEL TRANSLATE LOW LEVEL LANGUAGE
LANGUAGE (ALL) (LLL)/MACHINE LEVEL
LANGUAGE (MLL)
D.DEBUGER:-
INDENTIFY OR CHECK REMOVE THE ERROR IN
DEBUG
THE ERROR PROGRAM CODE
Visual Basic is event-driven, meaning code remains idle until called upon to
respond to some event (button pressing, menu selection,). Visual Basic is governed by an
event processor. Nothing happens until an event is detected. Once an event is detected,
the code corresponding to that event (event procedure) is executed. Program control is
then returned to the event processor.
Ans:- class:-A class is logical property of object, and which is a set of objects. Each object
of a class possesses same attributes and common behaviors define with in class. Normally
it is use to template of programming name.
Example: - Program Add of two numbers than you use class name “Add”.
Object:-Object is an entity that means hold by the unique value and which contains data &
function (Characteristics and behavior) together in an Object Oriented Programming
Language(OOP).Normally it is a Physical property of class.
Example:- Object name car and behavior & characteristics is (Speed, Color of car etc)
Ans :- constant:- Constant is an entity which value remain fixed doesn’t change.
Variable declare:- DIM <VARIABLE NAME > AS TYPE e.g. (DIM A AS Integer)
Ans:-Data type is type of data which identify a variable or constant which type of data are
contain or hold.
DATA TYPE
NUMERIC NON-NUMERIC
INTEGE
R FLOAT DOUBLE
5
A. Numeric
B. String
Use to store alphanumeric values. A variable length string can store approximately 4
billion characters
C. Date
Use to store date and time values. A variable declared as date type can store both date
and time values and it can store date values 01/01/0100 up to 12/31/9999
D. Boolean
Boolean data types hold either a true or false value. These are not stored as numeric
values and cannot be used as such. Values are internally stored as -1 (True) and 0
(False) and any non-zero value is considered as true.
E. Variant
Stores any type of data and is the default Visual Basic data type. In Visual Basic if we
declare a variable without any data type by default the data type is assigned as default.
6
14. What is the element of IDE (Integrated Development Environment) of VB6.0? and
Project Creation?
Ans :- The IDE environment consists of many elements. Some elements are displayed
when Visual Basic is started (By default) as in the following Figure. Other elements are
displayed if the user requires them. We will list some of these elements.
a- Menu Bar: It contains a standard command like: File, Edit, View, Window,
Help menus, and specific command such as: Project, Format, or Debug
menus.
c- Toolbox: it contains a collection of tools that are needed for project design.
f- Project Explorer Window: it is a list of the forms and modules for the
current projects. It is a hierarchical tree- branch structure, where the
project at top of tree and other parts like forms, modules) descend from
this tree.
g- Form Layout Window: The Form Layout window is a small screen. This is
used to reposition the form of the application so that it appears in proper
place when project is run.
h- Code Editor Window: Code Editor Window is used to write a VB code for
an application. For each form there is a separate code editor window. It is
displayed when user clicks on form or object in form.
(CODE WINDOW)
Controls - Graphical features drawn on forms to allow user interaction (text boxes,
labels, scroll bars, command buttons, etc.) (Forms and Controls are objects.)
Methods - Built-in procedure that can be invoked to impart some action to a particular
object.
Event Procedures - Code related to some object. This is the code that is executed when
a certain event occurs.
General Procedures - Code not related to objects. This code must be invoked by the
application.
9
There are three primary steps involved in building a Visual Basic application:
The Main Window consists of the title bar, menu bar, and toolbar
Toolbox
10
2) Picture box: Used to display images in any of the following formats: BMP, DIB
(bitmap), ICO (icon), CUR (cursor), WMF (metafile), EMF (enhanced metafile), GIF,
and JPEG.
6) Command button: Used as a switch (such as OK and Cancel) buttons. Code is written in
the Click event procedure of this control.
7) Check box: For a yes/ no (true /false) selection.
8) Option button: For selection as group. Many options are placed inside container
(grouped) (a Frame control). One control is selected from the group all others of the
group are automatically deselected.
9) Combo box: consists of (list and arrow when clicked a small a list appears), if user
selects item from the list, it will be displayed in Textbox. Vertical size is fixed.
10) List box: For a list, user adds to and deletes from this list. It takes any size.
14) Drive List Box: It is a special List Box filled automatically with names, of the files in a
specified directory. It is a list in variant.
15) Dir List Box: It is a special List Box filled with drives (Hard disc, Floppy, CD) in the
system. It is an invariant.
16) File List Box: It is a special List Box filled automatically with the names of all Dir List
Box. It is a list invariant.
17) Shape: Used only to display rectangles, circles, and ovals on the forms. Never raises any
events.
18) Line: Used only to display lines on the forms. It never raises any events.
19) Image: Used instead of Picture Box because it consumes fewer system resources.
Project
Project is a program designed to user application that may be simple (like calculator
program) or complex (like word program). Visual basic program can create many
types of projects.
a) To create project:
When program starts, project box appears>>> select Standard EXE Project window
appears. OR: File> >>New project>>> Box (select Standard EXE)>>> Project window
appears.
b) To add project:
Any number can be added. Project icon>>> Select Standard EXE
> >>Project window appears.
Note: Usually first project runs first, but user can change that by: Selecting project
from project window > mouse list > Set as startup.
d) To delete a project:
Select project in Project window > >>Mouse list >>> Remove project.
12
e) To save project:
The visual basic can save the project on disc in two ways, as an executable
type or a non- executable type.
1- Project file: it consists of all files which are related to specific project, also
some other information with it. This could be saved with extension (.VBP).
2- The form Files: this contains form description and any Object or program
related to it .This is saved with extension (.frm).
c) To save a form:
Select a form from Project window>File>>>Save project form1 as >>>
Save box (select form name). OR: File>Save project forml.
Forms
1) Introduction to form:-
The form is the most important visible object, without it no control can be displayed. It
is a window that can be designed and modified to fit user applications. In the standard
project the form Designer creates and modifies visual forms .When user starts visual
Basic program a form is automatically displayed in Designer window. The designer can
add any number of forms to the project of his application by pressing: add form from
project menu.
STOP icon
Start/RUN icon
User can interchange between them, by pressing on start icon or stop icon on tool bar.
The forms also have properties and events.
14
2) Form properties
Properties list has a predefined value (numeric or string) and could be changed, some
properties could be rewritten like caption, and some could be selected from option list
by pressing on down arrow on the side. Others could be rewritten or by browsing the
computer files when the user clicks on the dotted button on the right side a dialogue
box appears. The browsing button appears when the user clicks inside the box.
3) Code form
The code is written in code Form and it will be edited quickly by code editor .The codes are
of two categories:
4) Events:
Events are like electrical switches. The electrical switches are of many types,
so are the events. The forms and controls support events (generation,
interaction with mouse and keyboard). The most important events for the
form are described in the following table.
16
+ Add 5+5 10
- Subtract 10-5 5
/ Divide 25/5 5
\ Integer Division 20\3 6
* Multiply 5*4 20
^ Exponent (power of) 3^3 27
Remainder of
Mod 20 Mod 6 2
division
"George"&"
& String concatenation "George Bush"
"&"Bush"
Relational Operators
Logical Operators
Operators Description
OR Operation will be true if either of the operands is true, that means any
one condition/decision is true.
CONDITION1/DICISION1 CONDITION2/DICISION2 OUTPUT
AND
Operation will be true only if both the operands are true, that means
both are the condition/decision is true.
CONDITION1/DICISION1 CONDITION2/DICISION2 OUTPUT
c. Sign function:
If the number is
2 Positive ( number > 0 ) then sign value returned is “1”
3 Negative (number < 0 ) then sign value returned is “-1”
4 Zero (number = 0) then sign value returned is “0”
Dim N1 , N2 , N3 As Integer
N1 = 234
N2 = -19
N3 = 0
Print Sgn(N1)
Print Sgn(N2)
Print Sgn(N3)
------------------
the output is
1
-1
0
d. Format function:
1. Format(10203.192,”0000000.00000”)
2. Format(10203.192, “#####.#####”)
05 Result :- 10203.192 // no leading or trailing zeros
3. Format(10203.192, “$##,###.000”)
Result :- $10,203.192 // currency formatting