You are on page 1of 18

1

VISUAL BASIC
1. WHAT IS PROGRAMMING?

ANS: - A set of instruction is called a program. But Programming language


is an artificial language designed to communicate instructions to a machine,
particularly a computer. Programming languages can be used to create
programs that control the behavior of a machine and/or to express
algorithms precisely.

2. WHAT IS TRASLATOR?

ANS: - A translator is language processor which is translating high level


language to machine level language.

3. HOW MANY TYPES OF TRANSLATORS?

ANS:-

TRANSLATOR

COMPILER INTERPRETER ASSEMBLER DEBUGER

A. COMPILER:-

HIGH LEVEL LOW LEVEL LANGUAGE


LANGUAGE (HLL) (LLL)/MACHINE LEVEL
TRANSLATE AT ONCE / GLANCE
LANGUAGE (MLL)

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

5. WHAT IS VISUAL BASIC?


ANS: - Visual Basic is a tool that allows you to develop Windows (Graphic User Interface -
GUI) applications. The applications have a familiar appearance to the user.

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.

Event? Event processor

Basic Basic Basic


Event Code Code Code
Procedures

Some Features of Visual Basic

Full set of objects - you 'draw' the application


Lots of icons and pictures for your use
Response to mouse and keyboard actions
Clipboard and printer access
Full array of mathematical, string handling, and graphics functions
Can handle fixed and dynamic variable and control arrays
Sequential and random access file support
Useful debugger and error-handling facilities
Powerful database access tools
ActiveX support
Package & Deployment Wizard makes distributing your applications simple.
3

6. How many parts of Visual Basic Language?

Ans: - Normally It has Two Parts: - a) Component and 2) Control.

7. What is Application Program Interface?

Ans:-An application program interface (API) is a protocol intended to be used as an


interface by software components to communicate with each other. An API may include
specifications for routines, data structure, class, object, constant/literals and
variable/identifier. Such as Microsoft windows API, the libraries of a programming
Language.

8.What is Class and Object?

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)

9. What are a constant/literals and variable/Identifiers?

Ans :- constant:- Constant is an entity which value remain fixed doesn’t change.

Example: sun rise always East, a=10,a=10.5,a=’P’,a=”YCTC Garia”.

Constant name Format

Integer constant Only hold without decimal point value


e.g.(a=10)
Real constant Only hold with decimal point value
e.g.(a=10.25)
Character constant Only hold alphanumeric value that means
alphabets & numerical, denote by single
quote mark e.g.(a=’G’, a=’@’ & a=’10’ etc)
String constant Only hold set of or collection of character
value ,denote double quote mark ( a=”yctc
garia” etc)
Syntax constant declaration:- Const constant name = value
4

Variable:-variable is entity which value do not fixed remain changeable.

Example:- speed ,time etc

Variable name Format

Integer Variable Only hold without decimal point value


e.g.(a=10)
Real Variable Only hold with decimal point value
e.g.(a=10.25)
Character Variable Only hold alphanumeric value that means
alphabets & numerical, denote by single
quote mark e.g.(a=’G’, a=’@’ & a=’10’ etc)
String Variable Only hold set of or collection of character
value ,denote double quote mark ( a=”yctc
garia” etc)
Note: The Dim declaration written in general part of the form or in any place in form or sub
procedure which used for one form. While Global declaration used for all forms

10. How to declare variable and constant write with syntax?

Ans :- constant declare:- LET <VARIABLE NAME>=VALUE e.g.( LET A =10)

Variable declare:- DIM <VARIABLE NAME > AS TYPE e.g. (DIM A AS Integer)

Note :- DIM means Dimension OF VARIABLE.

11.What is Data Type/Type?

Ans:-Data type is type of data which identify a variable or constant which type of data are
contain or hold.

CLASSIFICATION OF DATA TYPE:-

DATA TYPE

NUMERIC NON-NUMERIC

REAL CHARACTER STRING


INTEGER
HOLD WITH DECIMAL ALPHANUMERIC SET OF
HOLD WITHOUT VALUE
DECIMAL POINT POINT VALUE CHARACRTER
VALUE VALUE

INTEGE
R FLOAT DOUBLE
5

A. Numeric

Byte Store integer values in the range of 0 - 255


Integer Store integer values in the range of (-32,768) - (+ 32,767)
Long Store integer values in the range of (- 2,147,483,468) - (+ 2,147,483,468)
Single Store floating point value in the range of (-3.4x10-38) - (+ 3.4x1038)
Double Store large floating value which exceeding the single data type value
store monetary values. It supports 4 digits to the right of decimal point and
Currency
15 digits to the left

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

12. What is Access Specifiers?

Ans:- Access Specifier are also known as visibility modes.

3 Types of Access Specifier:-

A) Private:-The data members (Instant variables/object) or member methods


which an specified as private can used only within the scope of a class. These members
are not accessed outside the class.

B) Public:-The class members (variables or methods) specified as public can be


used even outside the visibility of a class.

C) Protected:-The Protected members are used in the class as private members


which can only be applied within the class but can be inherited to another class.

13. How to open VB6.0?

Ans :- To run this program on user computer:

Start>>>programs>>>Microsoft Visual Studio 6.0>>>Microsoft Visual Basic 6.0.

It will appear on the computer screen as in the following picture.


7

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.

b- Toolbar: it contains the most commonly used commands (button), if clicked


an action represented by that button is carried out.

c- Toolbox: it contains a collection of tools that are needed for project design.

d- Form Designer: it is a window for each form to customize the designed


interface of the application. Using the form designer, the user can add
controls, graphics, and text to create the desired form appearance.

e- Properties Window: it is a List of properties settings for a selected form or


a control. These properties are characteristics (such as size, visible, or
color) of the selected object it provides an easy way to set properties.
8

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)

Structure of a Visual Basic Application

Application (Project) is made up of:

Forms - Windows that you create for user interface

Controls - Graphical features drawn on forms to allow user interaction (text boxes,
labels, scroll bars, command buttons, etc.) (Forms and Controls are objects.)

Properties - Every characteristic of a form or control is specified by a property. Example


properties include names, captions, size, color, position, and contents. Visual Basic
applies default properties. You can change properties at design time or run time.

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

Modules - Collection of general procedures, variable declarations, and constant


definitions used by application.
Steps in Developing Application

There are three primary steps involved in building a Visual Basic application:

1. Draw the user interface

2. Assign properties to controls

3. Attach code to controls

The Main Window consists of the title bar, menu bar, and toolbar

Toolbox
10

1) Pointer (not control): used to select tools already on form.

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.

3) Label: Fixed text appears on form for remark.

4) Textbox: For text edit .Like note pad.

5) Frame: To group tools together (container).

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.

11) Horizontal Scrollbar: Create stand-alone Horizontal scroll bars.

12) Vertical Scrollbar: Create stand-alone vertical scroll bars.

13) Timer: Used to control object movement.

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.

20) Data: used for data base.

21) OLE: used for joining with another programs.


11

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.

Following steps are followed:-

1. Working with Standard Projects:


The following working steps (create, save, add, open and delete) could be done:-

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.

c) To open an existing project:


It is previously designed and saved on disc in a folder.
File>>> Open project>>> Box (select existing and look for the project)
>>>Project window.

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.

Project in Non Execution Stage:

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).

a) To save project for first time:


File>>>Save project (group) as>>>Box (project name)>>> forms saved
Then Projects group saved.

b) To resave project: to save previously saved project in same place


File>>>save project (group).

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.

File> Make project.exe


13

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.

There are two modes: design mode and running mode.

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.

Form property table

PICTURE PICTURE URL SELECT FORM PICTURE RUN


15

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:

1- Declaration is written before any procedure in the code


2-Statements the user selects the required event then code statements are
written inside these event procedures.

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

15.Operators in Visual Basic


Arithmetical Operators

Operators Description Example Result

+ 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

Operators Description Example Result

> Greater than 10>8 True

< Less than 10<8 False

Greater than or equal


>= 20>=10 True
to

<= Less than or equal to 10<=20 True

<> Not Equal to 5<>4 True

= Equal to 5=7 False


17

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

TRUE TRUE TRUE

TRUE FALSE TRUE

FALSE TRUE TRUE

FALSE FALSE FALSE

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

TRUE TRUE TRUE

TRUE FALSE FALSE

FALSE TRUE FALSE

FALSE FALSE FALSE

NOT Operation of logically not


18

16. Use Of Function:


a. String function:
Dim lNum As Long
lNum = 1000
Text1.Text = Str$(lNum)
b. Val function:

Dim N1, N2, N3 as Integer


N1 = Val(text1.text)
N2 = Val(text2.text)
N3= N1*N2
Text3.text = Str(N3)

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”)

Result :- 0010203.19200 // leading and trailing zeros

2. Format(10203.192, “#####.#####”)
05 Result :- 10203.192 // no leading or trailing zeros
3. Format(10203.192, “$##,###.000”)
Result :- $10,203.192 // currency formatting

e. Date And Time :


Format (Now, “dddd,mmmm,dd,yyyy”)

Format (Now, “d-mmmm h:mm AM/PM”)

You might also like