You are on page 1of 9

c c c c c c

c
c
c
c
Index
S.noc ôescriptionc Signaturec Pagec
1c Introduction of VBc c 1c
2c Features of VBc c 2-3c
3c 21 controls in VBc c 4-6c
4c String funtionsc c 7-8c
5c ôate and time functionsc c 9c
6c Mathematical functionsc c 10-11c
7c c c c
c
c
c
c
c
c
c
c
c

 c is a tool that allows you to develop Windows (Graphic User Interface
-  ) applications. The applications have a familiar appearance to the user. As you develop as
a Visual Basic programmer, you will begin to look at Windows applications in a different light.
You will recognize and understand how various elements of Word, Excel, Access and other
applications work. You will develop a new vocabulary to describe the elements of Windows
applications
ORc

 c  (VB)is the third-generation event-driven programming
language and integrated development environment (IôE)from Microsoft for
its COM programming model. VISUAL BASIC is a high level programming language
which evolved from the earlier ôOS version called BASIC.BASIC means Beginners' All-
purpose Symbolic Instruction Code. Visual Basic is relatively easy to learn and use.The code
look a lot like English Language. ôifferent software companies produced different versions of
BASIC, such as Microsoft QBASIC, QUICKBASIC, GWBASIC ,IBM BASICA and so on.
VISUAL BASIC is a VISUAL and events driven Programming Language. These are the main
divergence from the old BASIC. In BASIC, programming is done in a text-only environment and
the program is executed sequentially. In VB, programming is done in a graphical environment.
In the old BASIC, you have to write program code for each graphical object you wish to display
it on screen, including its position and its color. However, In VB , you just need to drag and drop
any graphical object anywhere on the form, and you can change its color any time using the
properties windows. A programmer can put together an application using
the components provided with Visual Basic itself. Programs written in Visual Basic can also use
the Windows API, but doing so requires external function declarations.
On the other hand, because the user may click on a certain object randomly, so each object has
to be programmed independently to be able to response to those actions (events). Therefore, a
VB Program is made up of many subprograms, each has its own program code, and each can be
executed independently and at the same time each can be linked together in one way or another.
The final release was version 6 in 1998. Microsoft's extended support ended in March 2008 and
the designated successor was Visual Basic .NET
c
c
c
c


c c cc
c
Writing a graphical user interface program is much easier in Visual Basic. Visual Basic has a
very friendly environment, which helps to create forms, add controls to the form and write code
behind the form, very quickly and easily. Visual Basic also has an online help system. Visual
Basic (VB) is a unique computer language---at least it was when it first came out. Now there are
many imitators. VB allows you to quickly and easily develop a bank of visual controls with
sliders, switches and meters or a complex form for a user to fill out. This online help contains
thousands of programming examples. There are many other features in Visual Basic which are
discussed as follows:



c
 Visual Basic is


, 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. All Windows applications are event-driven. For example, nothing happens
in Word until you click on a button, select a menu option, or type some text. Each of these
actions is an event.

c

Visual Basic was Object-Based, Visual Basic .NET is Object-Oriented, which means that it's a
true Object-Oriented Programming LanguageEvery thing in Visual basic is an object. If a large
application is written, it can be broken into different compartments or objects and develop these
object separately.Visual Basic doesn¶t follow all the concepts and principles of object oriented
development as supported by VC++,and other development environment , a good object oriented
application ca be written.
 c
c
VB is a Graphical User Interface (GUI) language. This means that a VB program will always
show something on the screen that the user can interact with (usually via mouse and keyboard) to
get a job done. The first step in building the VB program is to get the GUI items on the screen.
This is done via pull-down menus that list the available graphical objects.


c
c !!c
Visual basic can be used to write Internet programs. Visual basic can be extended to other
environments, which means objects developed in Visual Basic can be used in other application
by the use of Active X controls, ôynamically Linked Libraries(ôôLs), and Add-Ins.
Some other features of vb:-
‡c Full set of objects - you 'draw' the application
‡c Lots of icons and pictures for your use
‡c Response to mouse and keyboard actions
‡c Clipboard and printer access
‡c Full array of mathematical, string handling, and graphics functions
‡c Can handle fixed and dynamic variable and control arrays
‡c Sequential and random access file support
‡c Useful debugger and error-handling facilities

c
"#c$cc cc%
c!!

c
c
$ To make forms more interactive or to make the front end of the application a totally
graphical user interface, controls are added to forms. The controls that you add to your forms
perform a wide variety of tasks including editing text, displaying pictures, and interfacing with
the database.
In Visual Basic, controls are a objects. ôesigned to perform specific tasks. Like form Objects,
controls have associated properties, events, and methods.

The following Table,list the standard controls and their functionality.

$c
!c
Labelc Most commonly used to display text that user cannot change.
c
TextBoxc Used to obtain information from the user or display
information.c
Framec Border or Container, used to visually or functionally Group
together related controls.c
CommandButtonc This control is used to trigger code when user clicks the
control.c
OptionButtonc Option Button selectionc
Listboxc ôisplay a list of values from which the user can select one or
more items.c
ComboBoxc Combines the features of TextBox control and ListBox
control. Users can enter information in the text box portion of
the control or select an item from the list box portion.c
Hscrollbarc Scroll horizontally.c
Vscrollbarc Scroll vertically.c
Timerc Trigger timed events.c
ôriveListBoxc Select a drive from the list.c
Filelist boxc Select a directory.c
Linec ôraw lines.c
Shapec ôraw shapes.c
ImageBoxc Used to display graphic.c
PictureBoxc Used to display connection to the database.c
OLEc OLE container.c

[    
        

    c
c
Alignmentc ôetermines whether text on the control, such as a label or
command button, is left-justified, centered,
or right-justified on the control.c
BackColorc Specifies the color of the control's background, which
you select from a palette of colors when you
open the property's drop-down list box of colors.c
BorderStylec ôetermines whether the control has a border around it.c
Captionc Lists the text displayed on the control.c
Enabledc Set by a drop-down list box, this property is either True if
you want the control to respond to the user
or False if you want the control not to respond to the
user. This property is useful for turning on and
off controls when they are and are not available during a
program's execution.c
Fontc ôisplays a Font dialog box from which you can set
various font properties, such as size and style, for a
control's text.c
ForeColorc Specifies the color of the control's foreground, which you
select from a palette of colors when you
open the property's drop-down list box of colors.c
Height c Specifies the number of twips high the control is.c
Leftc Indicates the starting twip from the left edge of the form
where the control appears. For a form, the
Left property specifies the number of twips from the left
edge of the screen.c
MousePointerc ôetermines the shape of the mouse cursor when the user
moves the mouse over the control at runtime.c
Namec Specifies the name of the control. As you saw in
yesterday's lesson, the Properties window displays the
Name property in parentheses so that it appears first in
the list of properties.c
ToolTipTextc Holds the text that appears when the user rests the mouse
cursor over the control at runtime (similar to
ScreenTips).c
Topc Is the starting twip from the top edge of the form where
the control appears. For a form, the Top
property describes the number of twips from the top edge
of the screen.c
Visiblec Set by a drop-down list box, this property is True if you
want the control to be visible on the form or
False if you want the control to be hidden from view.c
Widthc Specifies the number of twips wide that the control is.c

pc 
VB has numerous built-in string functions for processing strings. Most VB string-handling
functions return a string, although some return a number (such as the &
 function, which
returns the length of a string and functions like and '
, which return a character
position within the string). The functions that return strings can be coded with or without the
dollar sign (() at the end, although it is more efficient to use the version with the dollar sign
Function:c &
c

ôescription:c Returns a Long containing the length of the specified stringc

Syntax:c &
) *
Where  is the string whose length (number of characters) is to be
returned.c

Example:c lngLen = Len("Visual Basic") ' lngLen = 12c

Function:c a(c)ca*c

ôescription:c Returns a substring containing a specified number of characters from a string.c

Syntax:c a()    *


The Mid$ function syntax has these parts:
 Required. String expression from which characters are returned.
  Required; Long. Character position in string at which the part to be taken
begins. If start is greater than the number of characters in string, Mid
returns a zero-length string ("").
Optional; Long. Number of characters to return. If omitted or if there are
fewer than length characters in the text (including the character at start),
all characters from the start position to the end of the string are returned.c

Example:c strSubstr = Mid$("Visual Basic", 3, 4) ' strSubstr = "sual"


 a( can also be used on the left side of an assignment statement, where
you can replace a substring within a string.
strTest = "Visual Basic"
Mid$(strTest, 3, 4) = "xxxx"

'strTest now contains "Vixxxx Basic"


In VB6, the '
!
( function was introduced, which can also be used to
replace characters within a string.c

Function:c &
(c)c&
*c

ôescription:c Returns a substring containing a specified number of characters from the


beginning (left side) of a string.c

Syntax:c &
()  *
The Left$ function syntax has these parts:
 Required. String expression from which the leftmost characters are
returned.
 Required; Long. Numeric expression indicating how many characters to
return. If 0, a zero-length string ("") is returned. If greater than or equal to the
number of characters in string, the entire string is returned.
cc

Example:c strSubstr = Left$("Visual Basic", 3) ' strSubstr = "Vis"

' Note that the same thing could be accomplished with Mid$:
strSubstr = Mid$("Visual Basic", 1, 3)c

Function:c '%(c)c'%*c

ôescription:c Returns a substring containing a specified number of characters from the end
(right side) of a string.c

Syntax:c '%()  *


The Right$ function syntax has these parts:
 Required. String expression from which the rightmost characters are
returned.
 Required; Long. Numeric expression indicating how many characters to
return. If 0, a zero-length string ("") is returned. If greater than or equal to the
number of characters in string, the entire string is returned.c

Example:c strSubstr = Right$("Visual Basic", 3) ' strSubstr = "sic"

' Note that the same thing could be accomplished with Mid$:
strSubstr = Mid$("Visual Basic", 10, 3)c


cc
c cc c
ôate and Time are internally stored as numbers in Visual Basic. The decimal points represents
the time between 0:00:00 and 23:59:59 hours inclusive. The system's current date and time can
be retrieved using the Now, ôate and Time functions in Visual Basic. The Now function
retrieves the date and time, while ôate function retrieves only date and Time function retrieves
only the time.

To display both the date and time together a message box is displayed use the statement given
below.

a+c,-%
c
c
cc
c c%
c.
c,c/c0c
Here & is used as a concatenation operator to concentrate the string and the Now function.
Selective portions of the date and time value can be extracted using the below listed functions.
c +
c1c
Year ( )c Year (Now)c
Month ( )c Month (Now)c
ôay ( )c ôay (Now)c
Weekôay ( )c Weekôay (Now)c
Hour ( )c Hour (Now)c
Minute ( )c Minute (Now)c
Second ( )c Second (Now)c

c c c c c

a%
c c
The mathematical functions are very useful and important in programming because very often
we need to deal with mathematical concepts in programming such as chance and probability,
variables, mathematical logics, calculations, coordinates, time intervals and etc. The common
mathematical functions in Visual Basic are '2cp 2c 2c 2c+!2c&2cp2c$2c-c2c 2c
+ and '3

)*c ' is very useful when we deal with the concept of chance and probability. The Rnd
function returns a random value between 0 and 1. In Example 1.When you run the program, you
will get an output of 10 random numbers between 0 and 1. Randomize Timer is a vital statement
here as it will randomize the process.

+!
c#
ccccccccccPrivate Sub Form_Activate
Randomize Timer
For x=1 to 10
Print Rnd
Next x
End Sub
The numeric functions are , p , , +!, +, ' and &3

a)  is the function that converts a number into an integer by truncating its decimal part and the
resulting integer is the largest integer that is smaller than the number. For example, Int(2.4)=2,
Int(4.8)=4, Int(-4.6)= -5, Int(0.032)=0 and so on.
b) p is the function that computes the square root of a number. For example, Sqr(4)=2,
Sqr(9)=2 and etc.
c)  is the function that returns the absolute value of a number. So Abs(-8) = 8 and Abs(8)= 8.
d) +! of a number x is the value of ex. For example, Exp(1)=e1 = 2.7182818284590
e) + and  are the same if the number is a positive number as both truncate the decimal part
of the number and return an integer. However, when the number is negative, it will return the
smallest integer that is larger than the number. For example, Fix(-6.34)= -6 while Int(-6.34)=-7.
f) ' is the function that rounds up a number to a certain number of decimal places. The
Format is Round (n, m) which means to round a number n to m decimal places. For example,
Round (7.2567, 2) =7.26
g) & is the function that returns the natural Logarithm of a number. For example,
Log 10= 2.302585