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

VB-UNIT-1-Notes

Uploaded by

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

VB-UNIT-1-Notes

Uploaded by

Narenkumar. N
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

UNIT I

Visual Basic is a high level programming language evolved


from the earlier DOS version called BASIC. BASIC means Beginners All-
purpose SymbolicInstruction Code. The codes look a bit like English language.

FEATURES OF VB 6.0:-
▪ It is based on the BASIC language.
▪ Programming objects and Events.
▪ A common programming platform across all MS office
application.
▪ Native code Compilation.
▪ It Supports 32-Bit application.
▪ A quick and easy way to develop application.
▪ It includes many wizards that can automate tasks or even
automate coding.
▪ It includes new object types called FILE SYSTEM OBJECT
(FSO).
▪ It includes fourteen additional functions in VB6.0.
▪ It enables you to create ActiveX controls.
▪ Visual Basic6.0 includes ActiveX Data objects (ADO) as the
Visual data access tool.
▪ VB development environment includes extensive editing and
debugging tools.

CUSTOMIZING A FORM
IDE:
Visual Basic program are created in an INTERGRATED
DEVELOPMENT ENVIRONMENT (IDE). The IDE allows the programmer to
create, run and debug Visual Basic Programs conveniently. IDE allows a
program to create working programs in a fraction of the time that it would
normally take to code programs without IDEs.
FEATURES OF IDE:
➢ Break points can be toggled simply with a mouse click.
➢ Bookmarks can be placed for quick location.
➢ Properties in the property window can be manipulated
alphabetically or even by category.
➢ With a click of a mouse button, all highlighted code will be
commented or uncommented.
➢ Aligning and formatting can easily be applied to one or more
control.
➢ Applications in VB are developed in the Integrated
Development Environment (IDE).

COMPONENTS OF IDE:
1. Menu Bar 6. Code Editor Window
2. Tool Box Window 7. Form Layout Window
3. Form Window 8. Object Browser
4. Properties window 9. Context Menus
5. Project Explorer window 10. Standard Tool Bar

MENU BAR:
The Menu Bar helps you to perform various tasks. It is displayed
directly below the title bar and includes a list of options. Each option on the
Menu Bar has a drop-down list of items that are related to the option chosen
from the menu bar. Access keys and shortcut keys are provided for most of the
options.

File Edit View Project Format Debug Run Query Diagram Tools

AddIns Window Help


TOOLBOX WINDOW:
The toolbox is a window that provides you a set of
tools that are used at design time to place controls on a form. The buttons in the
toolbox depict controls. It contains more than 20 controls.
FORM WINDOW:
A form is one of the main building blocks in a VB application. You
can draw and view controls on a form. Forms are containers for controls. User
interacts with the controls on a form to obtain the desired result.

PROPERTIES WINDOW:
The properties window lists the design time properties for
selected objects and their current settings. A property is a characteristic of an
object such an size, Caption or colour etc.

Properties can be viewed alphabetically or by category by


clicking on the Alphabetic or categorized tabs in the properties window.

To view the properties window


View Properties Shortcut Key is F4.

PROJECT EXPLORER WINDOW:


The project explorer displays a hierarchical list of the
projects and all the items contained in a project.

The elements of project explorer window are

TOOL NAME DESCRIPTION


Shows you the code
View Code window

Shows you the Form


View Object Window
Views of hides the
Toggle Folders folders in the project
explorer.

To View the project explorer window

View Project Explorer

Shortcut Key is Ctrl+R.


COPY EDITOR WINDOW:
The code window is used to write, display and edit VB code.
The different code window elements are

Object List Box: Displays the name of the selected object.

Procedure/Events List Box: Lists all the events recognized by VB for a form
or control displayed in the object box. When you select an event, the event
procedure associated with that event name is displayed in the code window.

View Selection Button:

Two different views of the code are available in the code-editor window.
You can choose to view a single procedure or all the procedures in the
module at one time. Each procedure is separated from the next by a line.

To View code Editor window Double click on the particular control.

Shortcut Key is F7.

FORM LAYOUT WINDOW:

The Form Layout window allows you to visually position


the forms at design time. All forms that are visible in the environment are
shown in the Form Layout Window. The Forms can be repositioned with
the help of the mouse.

To View the Form Layout window


View Form Layout Explorer

OBJECT BROWSER:

It lists objects that can be used in the project and gives you a
quick way to navigate through the code. It also displays classes,
properties, methods, events and constants in your project. Objects from
other application can also be displayed.

To View the object browser

View object browser

Shortcut Key is F2.

CONTEXT MENUS:

VB provides context menus or shortcut menus that contain


frequently used commands. To open a context menu, click the right mouse
button on the object being used or press shift+F10.
TOOLBARS:

VB has four default toolbars. They are

• Standard
• Debug
• Edit
• Form-Editor
To View the Tool Bar

View Tool Bars

Standard Tool bar: The standard toolbar contains buttons that are shortcuts to
some commonly used menu items. Some of them are open project, save project,
cut, copy, paste, Add Form, etc….
Edit Tool bar: This toolbar contains items to assists in editing VB code.

Debug Tool bar: This toolbar contains items to assist in finding errors in the
code during a debugging session.

Form Editor Tool bar: This tool bar assist in adjusting item on the forms.

WRITING SIMPLE PROGRAMS:


▪ Create a new project by selecting New project from the File Menu
Option. When you start a new instance of VB, a new project is
created.
▪ Change the caption property of the form to sample and name
property to frm sample.
▪ Place a label and Text Box and command a form.
▪ Using the properties window, set the properties for each of the
controls on the form.
Object Property Settings
Form Name Frm Sample
Caption Sample
Label 1 Name Label 1
Caption First Number:
Label 2 Name Label 2
Caption Second Number:
Label 3 Name Label 3
Caption Result:
Textbox 1 Name Textbox 1
Textbox 2 Name Textbox 2
Textbox 3 Name Textbox 3
Command Button 1 Name Cmd Submit
Caption Submit

▪ Select the command button and Press F7 to invoke the code


window.

Private sub CmdAdd_Click( )

Txtresult.Text= Val(textbox1.Text)+ Val(textbox2.Text)

End sub
▪ Write the code for the click event.
▪ Save the project by selecting save project from the file menu
option.
▪ Save the form as sample.frm and the project as
sampleprg.vbp.
▪ Run the application by selecting start from the run menu
option or press F5.

FORM PROPERTIES:

Caption:

Caption property sets the title of the form. Caption is used to identify the
form when we minimize the application.

Name:

This property is used only in code. Returns the name used in code to
identify an object. The default name “FORM 1”. This property is different from
caption property.

Border Style:

Sets the border style of the object. Border style offersonly a small number
of choices. If you select the border style property you will get drop down list
box with values and description.

The default value 2-Sizeable

0 None No Border will appear


1 Fixed Single We cannot do any change in the form
2 Sizeable User can change the size and shape of the form
3 Fixed double Not often used in ordinary form
4 Fixed Tool This window is not used very often
window
5 Sizeable Tool Works much like the fixed tool window setting
Window

Enabled:
Set a value that determines whether an object can respond to user –
generated event.

True Enables the Form


False Disables the Form

Font:

Returns a Font Object. The property that set in an ordinary dialog box.

Startup Position:

Property gives you another way to decide on the initial position of your
form at run time. It is generally more precise than using the form layout
window.

VB CONTROLS:
Controls are used to get user input and display the output with the help of
controls; you can access remote application and data. Every control has
its own properties, methods and events.

Properties Used to change the appearance and the behaviour of


controls.
Events Actions recognized by a form or a control
Methods Cause an object to perform pre-defined action or task.

CATEGORIES OF CONTROLS:

Standard Controls Custom Controls


• Controls like command • These controls exist as
button, frame etc comes separate files with either
under this category. a.vbx or an.ocx extension.
• These controls are included • They include specialized
in the VB.exe file. controls like the common
• Standard controls are always dialog control and the Third
included in the toolbox. party custom control.
STANDARD CONTROLS:
LABELS:

A Label is a graphical control that is used to display text. It can


also be used to display text such as status messages and other program
Information.

PROPERTIES:

This property is used to change the


Caption text displayed in the label control.
This property is used to align the
text in the label.
Alignment 0---- Text is Left Aligned(Default)
1---- Right Aligned
2----Text at center
This property helps to resize the
Word-wrap text entered in the caption property,
if the text exceeds the width of the
label control, the text wraps to the
next line.
The property causes the control to
Autosize horizontally expand and adjust to
the size of its contents.

TEXT BOX:
A text box control is used to obtain fill in the blank information from the
user or to display information provided by the application.

PROPERTIES:

This property is used to give a name


Name to the text box, by which the text
box is identifiers in the code.
This property is used to set the text
Text contained in the edit are of the text
box. This is the default property.
This property determine whether a
Multi Line text box accept more than one line
of text when the user runs the
application.
This property determines the
Max Length maximum number of characters the
text box will accept.
This property determines whether a
text box has horizontal or vertical
scroll bars when single text box
contains multiple lines of data.
0 No horizontal and vertical
Scroll Bar scroll bar(default)
1 Only horizontal scroll bar
2 Only vertical scroll bar
3 Both horizontal and
vertical scroll bar
Border Style This property has the value is
1-> Fixed Value
0-> No border
Password The password property lets you
limit what the text box displays.
The convention is to use an
asterisk(*) for the password
character.

EVENTS:

Textbox can recognize 23 events. Events such as GotFocus,


LostFocus, KeyDown, KeyUp, KeyPress etc.

COMMAND BUTTON:

A Command button also known as push button is one of the mostly


commonly used controls in a user interface. The appearance of the
command button determines whether it is pressed or released.

PROPERTIES:

Caption This property determines the text displayed on


the command button.
Name This property returns the name used in the code
to identify the command button.
Value This property returns or sets values indication
whether the button is chosen.

EVENTS:

Click Occurs when the user presses and then releases a


mouse button over an object.
GotFocus Occurs when an object receives the focus, either by
user action, such as tabbing or clicking the object or by
changing the focus in code using the SetFocus method
LostFocus Occurs when an object loses the focus, either by user
action, such as tabbing or clicking another object or by
changing the focus in the code using the SetFocus
method.

FRAME CONTROL:

A Frame control acts as a container of other controls, typically option


buttons or check boxes.

PROPERTIES:

Visible This property returns or sets the value, indicating


whether the frame should be visible.
Caption This property specifies the text to be displayed as the
caption of the control.
Name This property assigns a name so as to identify the
frame in the program code.
Enabled This property is used to determine whether a control
can respond to user generated events.

OPTION BUTTON:
An option button is a round radio button that you select to turn an option
ON or OFF.

PROPERTIES:

Alignment This property determines the alignment of the option


button to caption.
Value This property returns or sets the state of the option
button.
Caption This property specifies the text that appears beside the
option button.
Name This property assigns a name to identify the option
button in the code.

CHECK BOX:
A check box control is used to give the user a True or False option. It
allows the user to select one or more options from a list of independent
options.
PROPERTIES:

Alignment This property determines the alignment of the check


box with respect to the caption.
This property used to specify the state of a check box.
Value False Check Box is deselected(default)
True Check Box is selected.
Caption This property specifies the text that appears beside the
check box.
Name This property assigns a name to identify the check box
in the code.
Enabled This property is used to set a value that determines
whether the checkbox can respond to user generated
events.

LIST AND COMBO BOX:

List boxes are used when you have a fixed list of choices. VB
automatically adds vertical scroll bars whenever the list box is too small for all
the items it contains.
PROPERTIES:

List This is a property of both list and combo boxes. This


gives you way to initialise the items in the list or
combo box instead of doing in at run time.
List Count It gives you the number of items on the list in both list
and combo boxes.
List Index The value of the listindex property gives the index
number of the highlighted item, which is where the
user has stopped list.
Text This property of both list and combo boxes and it gives
the currently selected item stored as a string.

THE NAME (CONROL NAME PROPERTY):-

This property determines the name visual basic uses for the event
procedures.

The limits on a control name are the same as for form names:

• The name must begin with a letter


• After that, you can use any combination of letters,
digits and underscores(Thus, no spaces are allowed in
a control’s name).
• The name cannot be longer than 40 characters.
THE MSGBOX AND INPUT BOX FUNCTION:

➢ The message box is one of the best ways to display a message to the user
during execution of the application.
➢ Unlike controls on a form, the message box that appears will pop up as a
dialog box.
➢ After the user reads the message displayed OK button should be clicked
to continue with the process.
➢ The message box not only displays data in a pop-up dialog box, it can
also display an icon or more action button for the user to choose from.
➢ It is capable of writing text data to the screen, which contains the message
one wants to display to the user.

SYNTAX:

MsgBox(“Message”);

EXAMPLE:

MsgBox(“This is a Message Box”)


IMAGE CONTROL:

Image controls hold Pictures. Image controls can be used to display icons
or pictures created with a program. Image control is in Tool Box.

PROPERTIES:

Border Style Image control has two possible settings.


0-> No border.
1-> Fixed border.
Stretch This is most important property in image control.
False-> Resize itself to fit the Picture(default).
True-> Picture resize to fit the control.

EVENTS:

Click Double Click Drag Drop


Mouse Down Mouse Move Mouse Up
OLE Drag Drop OLE Drag Over OLE Give Feed Back
OLE Start Drag OLE Set Data OLE Complete Drag

ACCESS KEYS:

To quickly activate a control or a menu item Access Keys are used.


We set the access key in caption property. We should use ampersand(&) symbol
before the letter you want to access.
THE GRID:

Grid is so important for accurately position controls, mastering it will help you
to give your application a finished, professional look.

Tools Options

PROPERTIES:

Show Grid You can turn the grid ON or OFF by changing the
show grid setting. The default setting is ON. There is
usually little reason to grid OFF.
Grid Width, The width and height text boxes let you set the distance
Grid Height (in twips) between grid marks. The default is 120
Boxes twips.
Align Controls The align control to Grid check box determine whether
to Grid controls automatically move to the next grid mark or
whether they can be placed between grid mark.

EDITIG TOOLS:-

VB also makes it easy to use a consistent indentation pattern for


the code. Indenting lines, as soon as, makes the code a lot easier to understand.
All these features are controlled by the editor pages in the Option dialog box
and the edit tool bar.

DATA TYPES:

VB provides several data types that allow you to represent different


types of data values.

Byte A Byte variable is stored as a single, unsigned 8-bit data value


(0 to 255).
Boolean To represent data that can have only two possible values, TRUE
or FALSE, the Boolean data type is used.
Integer To represent numbers you can use the integer data type. The
default value is 0.
Long To store data that could exceed the range specified for an integer
value, use the Long data type. The default value is 0.
Single A single data type is stored as a single precision floating point
number. If the number of decimal places exceeds the range of a
single precision floating point number, the last decimal place is
rounded.
Double The double precision data type can handle more decimal places
than the single data type. The default value is 0.
Currency The currency data type is used for calculations involving money
and for fixed point calculations.
Date Used to represent date and time values. When assigning values to
data type variables, they need to be enclosed within the hash sign
(#).
Object The object data type can be used to select the various objects and
controls provided by VB.
String To store data consisting of alphanumeric characters. A string
variable is initialized to empty.
Variant When you are not selected any data type for s variable while
declaring, by default VB assigns variables of variant data type.
It can store any type of data, expect fixed length string and user-
defined types.

VARIABLES:

A Variable is a name given to a location in memory where a data value is


stored. A variable has a name and a data type.

The Variable name is used to refer to the value in the variable and the
data type determines the type of data that the variable can store.

DELARATION OF VARIABLE:

You can declare a variable with the Dim statement.

SYNTAX:

Dim <var>[ As<type>]

EXAMPLE:

Single Variable: More than one Variable:

Dim Marks as Integer Dim Mark1, Total as Integer

Declaration of String Variable:

String variables are of two types

✓ Variable Length
✓ Fixed Length
Variable Length:

A String variable is by default of variable length. This means that


the size of the variable depends on the value that is assigned to it.

Example:

Dim str As String

Str=”Hello”

Then the length of str is 5

Fixed Length:

A fixed length string variable is a string variable whose size of the string
is assigned at design time. The size of the variable is fixed it remains constant.

Example:

Dim Name As String *20

We can store 20 characters in the variable name.

Type declaration characters:

A type declaration character is a symbol that specifies the data type of the
variable you can declare and specify the type of the variable by using a type
declaration characters.

Type Declaration Character Data Type


% Integer
$ String
@ Currency
& Long
# Double
! Single
Example:

Dim Num%

- Declares the variables Num as Integer data Type.

You might also like