0% found this document useful (0 votes)
15 views

173004675859_Faculty E Notes Unit 1 Introduction To Visual Basic

Gh

Uploaded by

khushisachdeva45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

173004675859_Faculty E Notes Unit 1 Introduction To Visual Basic

Gh

Uploaded by

khushisachdeva45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Additional knowledge material

Faculty E- Notes

COURSE BCA- Vth SEM


UNIVERSITY MDU
SUBJECT VISUAL BASIC
UNIT UNIT-1
SUBJECT CODE BCA-304
NAME OF FACULTY LIPIKA BATRA

1
TABLE OF CONTENTS
S.No. Topic Page No.
1. Introduction to Visual Basic 3
2. Procedural Oriented Programming 6
3. Object Oriented Programming 7
4. Difference between Procedural and Object-Oriented 8
Programming
5. Event Driven Programming 9
6. Visual Basic Integrated Development Environment 10-26

2
1. Introduction to Visual Basic
Visual Basic is a third-generation event-driven programming language first released by
Microsoft in 1991. It evolved from the earlier DOS version called
BASIC. BASIC means Beginners' All-purpose Symbolic Instruction Code. Since then,
Microsoft has released many versions of Visual Basic, from Visual Basic 1.0 to the
final version Visual Basic 6.0.

Visual Basic is a user-friendly programming language that enables anyone to develop


GUI window applications easily.

Visual Basic has two parts:


• Visual: Refers to the method used to create GUI (Graphical User Interface).
• Basic: Refers to the BASIC language.

Note:
• Visual Basic is a tool that allows you to develop Windows (GUI)
applications.
• The Visual part in Visual Basic refers to the method used to
create GUI.
• The Basic part in Visual Basic refers to the “BASIC” language.
VB is much enhanced version of the BASIC programming
language. VB contains large number of statements, built-in
functions and keywords, many of which directly relate to the
Windows GUI.
• VB is one of the first programming languages which
incorporates WYSIWYG, i.e.,
What You See is What You Get environment.
• VB supports Event Driven Programming.

3
1.1Visual Programming and Non-Visual Programming
Visual programming is a way of creating software programs or applications by using
visual components like buttons, checkboxes, dialog boxes, forms, etc. This approach
allows users to drag and drop pre-built components and connect them together to create
an application.

In Non-Visual Programming, one has to create programme textually, no GUI is there,


only Text based interface.

Visual Programming Non-Visual Programming


1. Uses pictorial representation 1. Uses textual representation for
for programs. programs.
2. Provides GUI. 2. Provides command line
interface.
3. Provides Point and Click 3. Provides remember and type
interface. interface.
4. Easy to understand. 4. Difficult to understand.
5. Provides efficient 5. Everything appearing in a
representation for some program needs to be encoded
structures like table, tree or as text.
graph, etc.
6. Pictures are more powerful 6. Less powerful means of
than words as a means of communication.
communication.
7. Pictures don’t have the 7. Language barriers exist.
language barriers that natural
language have.
8. More flexible style. 8. Less flexible style
9. Less time is required to design 9. Time consuming process to
the user interface. design the user interface.
10. Provides tools for quick 10. Editing, testing and
editing, testing and debugging are difficult and
debugging. time consuming as compared
to visual programming.

4
1.2Features of Visual Basic
a) Easy to learn and use: The syntax is so simple that one can easily use and understand
the commands.
b) Built-in capability to create User Interface: User interface can be easily created by
using the tools available with VB.
c) Quick development: Programming time is reduced as compared to other command
line programming languages because VB has got built-in capability to create user
interface.
d) Event Driven Programming: VB supports event driven programming.
e) Common Programming Platform: VB provides a common programming platform
across all MS-Office applications.
f) Wizards: VB provides many Wizards that can automate tasks or even automate coding.
g) N-Tier Architecture: A traditional client/server model has two layers. In two tier
architecture, there is no middle layer of application between the client and the server.
However, if there are some layers between client and server, then, such an architecture
is known as n-tier architecture. VB supports n-tier architecture.
h) Quick Error Detection/Correction: The VB development environment provides tools
for quick editing, testing and debugging.
i) Database Support: VB provides database connectivity support for most popular
databases like Microsoft SQL Server and other enterprise level database.
j) ActiveX Support: ActiveX technologies allow to use the functionality provided by
other applications, such as, Microsoft Word, Microsoft Excel spreadsheet and other
Windows applications.
k) Internet Features: Internet capabilities make it easy to provide access to documents
and applications across the Internet from within your application.
l) Object Oriented Features: VB supports all object-oriented language features like
classes, encapsulation, data hiding, etc.
5
m) Both Interpreted and Compiled: VB is both interpreted and compiled. You can test a
VB program by running it interpretively until you debug it completely and then
compile it for faster execution when all the bugs are eliminated.

2. Procedural – Oriented Programming


Procedure oriented programming basically consists of writing a list of instructions for
the computer to follow and organizing these instructions into groups known as
functions. This programming language follows a step-by-step approach to break down
a task into a collection of variables and routines (or subroutines) through a sequence of
instructions. In procedural programming, the main program is divided into small parts
based on the functions and is treated as separate program for individual smaller
program. We normally use flowcharts to organize these actions and represent the
flow of control from one action to another.

Some Characteristics exhibited by procedural-oriented programming are:


▪ Emphasis is on doing things (algorithms).
▪ Large programs are divided into smaller programs known as functions.
▪ The approach being function-oriented, data is given least importance.
6
▪ Most of the functions share global data.
▪ Globalization of data leads to loss of important information.
▪ Data move openly around the system from function to function.
▪ Programs are more complex to write and maintain.
▪ Modification and addition of new functions are difficult.
▪ Doesn’t model the real world very well.
▪ Employs top-down approach in program design.

3. Object-Oriented Programming
The major motivating factor in the invention of object-oriented approach is to remove
some of the flaws encountered in the procedural approach. OOP treats data as a critical
element in the program development and does not allow it to flow freely around the
system.

OOP approach binds the data and the functions that operate on that data into a single
entity. Such an entity is called an object. It ties data more closely to the function that
operate on it, and protects it from accidental modification from outside function. OOP
allows decomposition of a problem into a number of entities called objects and then
builds data and function around these objects.

7
Object-oriented program typically consists of a number of objects which communicate
with each other by calling one another’s member functions. Calling an object’s member
function is also referred to as sending a message to the object.
Some Characteristics of Object-Oriented Programming are:
▪ Emphasis is on data rather than procedure.
▪ Programs are divided into what are known as objects.
▪ Data structures are designed such that they characterize the objects.
▪ Functions that operate on the data of an object are tied together in the data structure.
▪ Data is hidden and cannot be accessed by external function.
▪ Objects may communicate with each other through function.
▪ New data and functions can be easily added whenever necessary.
▪ Follows bottom-up approach in program design.

4. Difference between Procedural-Oriented and Object-Oriented Programming

Procedural Oriented Programming Object-Oriented Programming

In procedural programming, the In object-oriented programming, the


program is divided into small parts program is divided into small parts
called functions. called objects.

Procedural programming follows Object-oriented programming


a top-down approach. follows a bottom-up approach.

Object-oriented programming has


There is no access specifier in access specifiers like private, public,
procedural programming. protected, etc.

Adding new data and functions is not Adding new data and function is
easy. easy.

8
Procedural Oriented Programming Object-Oriented Programming

Procedural programming does not Object-oriented programming


have any proper way of hiding data so provides data hiding so it is more
it is less secure. secure.

In procedural programming, Overloading is possible in object-


overloading is not possible. oriented programming.

In procedural programming, there is In object-oriented programming, the


no concept of data hiding and concept of data hiding and
inheritance. inheritance is used.

In procedural programming, the In object-oriented programming, data


function is more important than the is more important than function.
data.

Procedural programming is based on Object-oriented programming is


the unreal world. based on the real world.

Object-oriented programming is used


Procedural programming is used for for designing large and complex
designing medium-sized programs. programs.

Procedural programming uses the Object-oriented programming uses


concept of procedure abstraction. the concept of data abstraction.

Code reusability absent in procedural Code reusability present in object-


programming, oriented programming.

9
Procedural Oriented Programming Object-Oriented Programming

Examples: C, FORTRAN, Pascal, Examples: C++, Java, Python, C#,


Basic, etc. etc.

5. Event Driven Programming


Event-Driven programming focusses on events. In this model, programs are no longer
procedural and don’t follow a sequential logic. Instead the user can click on a particular
picture (button or icon) available on the screen which causes an event to occur and a
basic procedure (or code) is executed in response to this event.
An event refers to the occurrence of a user-action, such as, when the user clicks the
mouse or when the user presses a key on the keyboard, etc.
In event-driven programming, nothing happens until an event is detected. Once an
event is detected, the code corresponding to that event is executed.

6. Visual Basic Integrated Development Environment (IDE)

10
The Visual Basic environment consists of eight main windows which are listed as
follows
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.

11
f- Project Explorer Window: It is a list of the forms and modules for the current
projects. lt is a hierarchical tree- branch structure, where the project lies at the
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. Which is
used to reposition the form of the application so that it appears in proper place
when project is run.
h- Code Editor Window: It 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.
6.1 Menu Bar:
The Menu Bar in Visual Basic refers to the horizontal strip of options that contains
various commands and functions. It is an essential component of the Visual Basic
integrated development environment (IDE) that allows developers to navigate and
access different tools and features.

Commands for importing, saving, exporting and


File
removing files.
Commands for formatting and writing code in the
Edit
code editor.
Commands for showing and hiding the different
View
components.
Commands for inserting subroutines, functions and
Insert
different types of modules.
Commands for designing and arranging controls on a
Format
user form.

12
Commands for debugging and stepping through
Debug
code.
Commands for testing code and displaying user
Run
forms.
Commands for accessing additional references and
Tools
user options.
Commands for loading and unloading additional
Add-Ins
COM add-ins.
Commands for quickly switching between all the
Window
open windows.
Help Commands for accessing the built-in help files.

13
6.2 Toolbox
It is a collection of pre-built controls, components, and tools that simplify the
process of creating applications. From buttons and text boxes to menus and dialog
boxes, the toolbox provides a wide range of elements that can be easily dragged and
dropped onto the interface, saving time and effort for developers.

Control Description
Pointer Used to interact with controls on the form (resize
them,move them, etc.). The pointer is not a control
PictureBox A control that displays images or prints the result.
Label A control that displays un-editable text to the user.
TextBox A control for accepting user input. Textbox can also
display text.
Frame A control for grouping other controls.
CommandButton A control that represents a button. The user presses or
clicks to initiate an action.
CheckBox A control that provides the user with a toggle choice
(checked or unchecked)
OptionButton Option buttons are used in groups where only one at a time
can be true.
ListBox A control that provides a list of items.
ComboBox A control that provides a short list of items.
HscrollBar A horizontal scrollbar.
14
VscrollBar A vertical scrollbar.
Timer A control that performs a task at programmer specified
intervals. A timer is not visible to the user.
DrivelistBox A control accessing the system disk drivers.
DirlistBox A control accessing directories on a system
Filelistbox A control accessing file in a directory
Shape A control for drawing circles, rectangles, squares or
ellipse
Line A control for drawing line.
Image A control for displaying images. The images control
does not provide as many capabilities as a picturebox.
OLE A control for interacting with another window
applications.

i. The Label
The label is for providing instructions and guides to the users, as well as for
displaying outputs. One of its most important properties is Caption. Using the
syntax Label.Caption, it can display text and numeric data. You can change its
caption in the properties window and also at runtime.
ii. The Command Button
The command button is used for executing a procedure triggered by an event
initiated by the users. The most common event associated with the command button
is the Click event, and the syntax for the procedure is:
Private Sub Command1_Click ()
Statements
End Sub
iii. The PictureBox
The Picture Box is one of the controls that is used to handle graphics. One can load a
picture at design phase by clicking on the picture item in the properties window and
select the picture from the selected folder. One can also load the picture at runtime
using the LoadPicture method. For example, the statement will load the picture
grape.gif into the picture box.

15
Picture1.Picture=LoadPicture ("C:\VBprogram\Images\grape.gif")
iv. The Image Control
The Image Control is another control that handles images and pictures. It functions
almost identically to the pictureBox. However, there is one major difference, the
image in an Image Box is stretchable, which means it can be resized. This feature is
not available in the PictureBox. Similar to the Picture Box, it can also use the
LoadPicture method to load the picture.
v. The ListBox
The function of the ListBox is to present a list of items where the user can click and
select the items from the list. In order to add items to the list, we can use
the AddItem method. The items in the list box can be identified by
the ListIndex property. The value of the ListIndex for the first item is 0, the second
item has a ListIndex 1, and the third item has a ListIndex 2 and more.
vi. The ComboBox
The function of the Combo Box is also to present a list of items where the user can
click and select the items from the list. However, the user needs to click the small
arrowhead on the right of the combo box to see the items which are presented in a
drop-down list. In order to add items to the list, you can also use the AddItem
method.
vii. The CheckBox
The Check Box control lets the user selects or unselects an option. When the Check
Box is checked, its value is set to 1 and when it is unchecked, the value is set to
0. You can include the statements Check1.Value=1 to mark the Check Box and
Check1.Value=0 to unmark the Check Box.
viii. The OptionButton
The OptionButton control also lets the user selects one of the choices. However, two
or more Option buttons must work together because when one of the option buttons
is selected, the other Option button will be unselected. In fact, only one Option Box
16
can be selected at one time. When an option box is selected, its value is set to “True”
and when it is unselected; its value is set to “False”.
ix. The Shape Control
In the following example, the shape control is placed in the form together with six
OptionButtons. To determine the shape of the shape control, we use the shape
property. The property values of the shape control are 0, 1, and 2,3,4,5 corresponding
to a rectangle, a square, an oval shape, a circle, a rounded rectangle and a rounded
square respectively.
x. The DriveListBox
The DriveListBox is for displaying a list of drives available in your computer. When
you place this control into the form and run the program, you will be able to select
different drives from your computer.
xi. The DirListBox
The DirListBox means the Directory List Box. It is for displaying a list of directories
or folders in a selected drive. When you place this control into the form and run the
program, you will be able to select different directories from a selected drive in your
computer.

6.3 ToolBar
Contains several icons that provide quick access to commonly used features.

17
6.4 Form Designer Window:
This window contains a form, which is where the program’s Graphical User
Interface (GUI) will be displayed. A GUI is the visual portion of the program, this is
where the user enters data (called inputs) to the program and where the program
displays its results (called outputs). Forms are the foundation for creating the
interface of an application. You can use the forms to add windows and dialog boxes
to your application. You can also use them as container for items that are not a
visible part of the application’s interface. For example, you might have a form in
your application that serves as a container for graphics that you plan to display in
other forms.

Visual Basic Form is the container for all the controls that make up the user
interface. Every window you see in a running visual basic application is a form,
thus the terms form and window describe the same entity. Visual Studio creates
18
a default form for you when you create a Windows Forms Application.
Form Properties
Following table lists down various important properties related to a form. These
properties can be set or read during application execution. You can refer to
Microsoft documentation for a complete list of properties associated with a Form
control –

19
Sl.No Properties Description
1 AcceptButton The button that's automatically activated when
you press Enter, no matter which control has
the focus at the time. Usually the OK button
on a form is set as
AcceptButton for a form.
2 CancelButton The button that's automatically activated
when you hit the Esc key.
Usually, the Cancel button on a form is set as
CancelButton for a form.
3 AutoScale This Boolean property determines whether the
controls you place on the form are
automatically scaled to the height of the
current font. The default value of this
property is True. This is a property of the form,
but it affects the controls on the form.
4 AutoScroll This Boolean property indicates whether scroll
bars will be automatically attached to the form
if it is resized to a point that not all
its controls are visible.
5 AutoScrollMinSize This property lets you specify the minimum
size of the form, before the scroll bars are
attached.
6 AutoScrollPosition The AutoScrollPosition is the number of
pixels by which the two scroll bars were
displaced from their initial locations.
7 BackColor Sets the form background color.

20
8 BorderStyle The BorderStyle property determines the style
of the form's border and the appearance of
the form −
• None − Borderless window that can't be
resized.
• Sizable − This is default value and
will be used for resizable window that's
used for displaying regular forms.
• Fixed3D − Window with a visible
border, "raised" relative to the main
area. In this case, windows can't be
resized.
• FixedDialog − A fixed window, used
to create dialog boxes.
• FixedSingle − A fixed window with a
single line border.
• FixedToolWindow − A fixed window
with a Close button only. It looks like the
toolbar displayed by the drawing and
imaging applications.
• SizableToolWindow − Same as the
FixedToolWindow but resizable. In

21
addition, its caption font is smaller than
the usual.
9 ControlBox By default, this property is True and you can
set it to False to hide the icon and
disable the Control menu.
10 Enabled If True, allows the form to respond to
mouse and keyboard events; if False,
disables form.
11 Font This property specify font type, style, size
12 HelpButton Determines whether a Help button should be
displayed in the caption box of the form.
13 Height This is the height of the Form in pixels.
14 MinimizeBox By default, this property is True and you can
set it to False to hide the Minimize button on
the title bar.
]15 MaximizeBox By default, this property is True and you can
set it to False to hide the Maximize
button on the title bar.
16 MinimumSize This specifies the minimum height and
width of the window you can minimize.
17 MaximumSize This specifies the maximum height and
width of the window you maximize.
18 Name This is the actual name of the form.
19 StartPosition This property determines the initial position of
the form when it's first displayed. It will have
any of the following values −
• CenterParent − The form is centered in
the area of its parent form.
• CenterScreen − The form is centered on
the monitor.
• Manual − The location and size of the
form will determine its starting position.
• WindowsDefaultBounds − The form is
positioned at the default location and
size determined by Windows.
• WindowsDefaultLocation − The form is
positioned at the Windows default
location and has the dimensions
you've set at design time.
20 Text The text, which will appear at the title bar
of the form.
21 Top, Left These two properties set or return the
coordinates of the form's top-left corner in
pixels.

22
22 TopMost This property is a True/False value that lets you
specify whether the form will remain on top of
all other forms in your application. Its
default property is False.
23 Width This is the width of the form in pixel.

6.5 Properties Window


The properties window displays the properties for a form or control.
Properties are attributes such as size, position, etc. like a form; each
control type has its own set of properties. Some properties, like width
and height, such as, are common to both forms and controls, while
other properties are unique to form or control. Controls often differ in
the number and type of properties. Properties are listed either
alphabetically (by selecting the alphabetic tab) or categorically (by
selecting the categorized tab). The most important properties of the
objects in general are listed in the following table. To show the
properties window, press View>
properties window icon.

Properties Objective
name
Name Used to represent
name of object in code.
Caption Name appears
on object.
Back Background color
color for object.
Fore Color of text written
color on object.
Font Font style type and
size
Visible The tool is visible
or invisible.

23
Enable The tool enable
or disable
Height Length of object

Width Width of object

Top Coordinates of top of


object on screen
Left Coordinates of left of
object on screen
Text Allows inputting
and editing text in
object.

6.6 Project Explorer Window


The window titled Project-Project1 is called the Project Explorer and
contains the project files. The project explorer window’s tool bar
contains three buttons, namely view code, view object and toggle
folders. When pressed, the view code button displays a window for
writing Visual Basic code. View object, when pressed, displays the
form. Double-clicking form1 (form1) also displays the form. The
toggle folders button toggles (i.e., alternately hides or shows) the forms
folder. The forms folder contains a listing of all forms in the current
project. To show the Project Explorer window press View> Project
Explorer window icon.

24
6.7 Form Layout Window
The Form Layout window specifies a form’s position on the screen at
runtime. The Form Layout window consists of an image representing

the screen and the form’s relative position on the screen. With the
mouse pointer positioned over the form image, drag the form to a new
location.

As mentioned, the user interface is ‘drawn’ in the form window.


There are two ways to place controls on a form:

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,

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

6.8 Code Editor Window


This is the window where you write the code.

26

You might also like