You are on page 1of 35

Acknowledgement

No word would probable suffice to appropriately


acknowledgement my deep gratitude to esteem teacher and
guide am heartily thankful to my lecturer Ms. XXXX XXXX
whose encouragement, guidance and support from initial to
the final level enabled me to develop an understanding of
this.

It is pleasure to thank those who made this project


possible. She has made available her support in a number of
ways.

Also I wish to thank all of those who helped me, without


them I could not have completed this project.

Lastly, I offer my regards and blessing to all of those who


supported me in any respect during the completion of the
project.
Index

Topics Teacher Sign

Introduction to visual basic


Object-related concepts
Visual basic Integrated Development
Environment (IDE)
Controls
Data Types
Input box function
Msg Box Function
Loop Statements

Programs:-

1. Program to show use of check box, radio buttons and


frames.
2. Program to display grade using Switch case.
3. Program to find greatest number between three
numbers.
4. Program to show the use of drive box, directly box,
file box.
5. Program to draw Different Shapes.
6. Program of Stopwatch using Timer.
7. Program to design a simple calculator.
Visual Basic 6.0

Visual basic is a tool that allows you to develop windows


(GUI-Graphical User Interface) applications.

Visual Basic

Visual Part Basic Part

(The visual part refers to (The basic part refers to the


BASIC language. VB is a much
The method User to create
enhanced version of the BASIC
GUI) programming language. VB
contains large number of
statements, built-in functions and
Keywords, many of which relate
directly to the windows GUI)

It is one of the first programming language which is


incorporates W Y S I W Y G i.e. what you see is what
you get environment.
VB supports event driven programming.
Object-related concept in VB

The object-related concepts in VB are:-

a) Forms

In VB, a window is called a form. All applications in VB use at least


one form. You can place version controls on the forms. Each form
contains a title bar as shown in figure.

b) Controls

The icons with which the user interacts are called controls.

c) Objects

Forms and controls are referred to collectively as objects.

d) Properties

A property is a characteristic of an object such as its size, its


caption or its colour etc.

e) Methods
A method in VB is a predefined action that operates on a
specific object (i.e. form of control). For example, set focus
method is used to move the specific object.
Visual Basic Integrated Development Environment (IDE)

Once you start VB, several different items appear on your screen.
Together these items represent the VB Integrated Development
Environment (IDE).

Tools Box
Project explorer or simply project window
Properties Window
Form layout window
Title Bar
Menu Bar and pull down menus
Toolbar
Form Designer
Immediate Window
Controls

1 Pointer Control This is only item on the tools box


that does not draw a control it is
used to select, resize or move a
control.
2 Picture Used to display graphical images.
3 Label Used to display text that a user
cant change directly.
4 Frame Used to separates difference
groups of control on frame.
5 Text box Used to display text and enter
the information
6 Command Button Used to give a command like
begin.
7 Check Box Used to allow a user select
multiple choices. For example a
student can choose any four
subjects out of availed 10
subjects.
8 Option button Used to display/select an option
from a set of options. For
example a student can opt one
medium of exam.
9 List Box Used to display a list of items
from which a user can select one
item.
10 Combo Box It contains the features of a text
and a list box control. So user can
enter information or select an
item from the list.
11 File List Box Use to locate and list files in the
directory whose location or path
has been specified by directory
list box.
12 Shape Used to display a rectangle,
square, oval, circle, etc.
13 Line Used to display a horizontal,
vertical line.
14 Image The image control is used to
display a graphic of different
available formats such as bitmap,
gif, jpg, etc.
15 Data Used to perform data access
operations.
16 OLE OLE stands for object Linking and
embedding. It is used to
add/insert objects to your forms
e.g. insertion of an excel sheet, a
PowerPoint slide.
17 Scrollbar Used to draw horizontal and
vertical scroll bars.
18 Drive List Box Used to select valid disk drive.
19 Directory List Box Used to select directory and path
20 Timer Used to execute timer event at
specified time interval.
Data Types

Sr. No. Data Storage Size Description


Type
1 Byte 1 byte (8 This data type allows only
bits) positive integer in the
range 0 to 255
2 Integer 2 byte (16 It can hold integer (without
bits) fractional values). Range is
-32768 to 32767
3 Long 4 byte (32 Store Long integer values
bits)
4 Single 4 byte (32 It holds Single precision
bits) values. It allows up to 6
digits of precision.
5 Double 8 byte (64 It holds Double precision
bits) values. It allows up to 14
digits of precision.
6 Currency 8 byte (64 It is used to hold the
bits) currency data. It allows up
to 4 digits of precision.
7 Boolean 2 bytes (16 It takes only two values,
bits) true or false.
8 Date 8 byte (64 It is used to hold date and
bits) time values. It can store
dates in range January 1,
100 to December 31, 9999.
9 String String length It is used to hold multiple
(fixed characters. For fixed
length) length string, range is 1 to
65,4000.
10 String String length Range for variable length
(variable string is 0 to 2 billion
length) characters.
11 Object 4 byte It is used to hold and refer
to object such as controls
and forms.
12 Variant 16 bytes It can hold data of any type
(Numeric) except fixed length string
or user defined data types.
If it holds only numeric
values, then its size is 16
bytes.
13 Variant Length+22 It is come as variable
(Text) bytes length sting.
Input Box Function

The input box function s used to read data from the user.
This function displays a dialog box that asks the user to
enter some data.

The following figure shows a simple input box:

Syntax of input box function is :

Memory_variable=InputBox(prompt, [title], [default],


[xpos], [ypos])

Where

Memory_variable is a variant or string


Prompt is a string expression that is display as the message in the
dialog box.
Title is a expression that is displayed in the title bar of the dialog box.
If you omit the title, the application name is displayed in the title bar.
Default is a string expression that appears in the input box as the
default value if no other input is provided.
Xpos & Ypos are the coordinates of the input box.
Msg Box Function

A Message box is used to display a message to the user. You


can display a message, an optional icon, and title bar caption
and command button (s) in a message box. The msgbox
function displays a message in a dialog box, waits for the
user to click a button, and returns an integer indicating
which button the user click.

Syntax of msgbox function is:

Msgbox(prompt[,button][,title][,helpfile, context])

Where

Prompt is a string expression that is displayed as the


Message in the dialog box. The maximum length of prompt is
1024 characters.

Buttons is a numeric expression that is the sum of values


specifying the number and type of buttons to display the
icon style to use and the identity of Default button. If
omitted, the default value for button is 0 (Which causes
only an ok button to be displayed with no icon).

Title is a string expression that is displayed in the title bar


of the dialog box. If you omit title, the application name is
placed in the title bar.

Help field and Context File has been set up to work with
the application.
Loop Statements

Loop statements execute a set of statements repetitively


based on a condition visual basic provides following types of
loops:

For-next
For each-next
While-wend
Do-Loop

For-next loop: The For-next loop execute a set of


statements a certain number of time.

Syntax:

For counter = start to end

Statement(s)

Next counter

Here the start and end are the initial and final values of the
variable counter. Initially the value of counter is set to
start and it increase by 1 each time the loop is executed,
until it reaches end. Here the next statement identifies the
end of the loop.

Nested for loop: Using a for-next loop inside another for


next loop is called as nested for .. next loop.

For each-next loop: The for-each-next loop executes a set


of statements on each element of collection.
Syntax:

For each element in group

Statement(s)

Next element

This loop executes the statements for each element in the


group. While using for each loop, one should take care that
the element can only be a variant variable.

While-Wend Loop: The while-wend loop executes the


statements as long as the given condition is true.

Syntax:

While Condition

Statements

Wend

Here the condition is an expression that evaluates to true


or false. The statements between while and wend keeps on
executing till the condition evaluates to true.

Do-loop Statements: The do-loop comes in many variants


using the do and loop keywords, such as do-while loop, do-
loop while, do until loop until.
Do-While Loop:

Syntax:

Do while condition

Statements

Loops

Here if the condition is true then it executes statements, it


goes back to examine the condition. The condition is
evaluated once again and this process goes on until the
condition becomes false.

Do-Loop While:

Syntax:

Do

Statements

Loop While condition

Here statement(s) executes first and then the condition is


evaluated. If the condition is true then it executes
statements again. After executing the statements, the
condition is evaluated once again. And this process goes on
until the condition becomes false.
Do-Until loop:

Syntax:

Do until condition

Statement(s)

Loop

Here if the condition is False then it executes


Statement(s). After executing the statement(s), it goes
back to examine the condition. The condition is evaluated
once again. And this process goes on until the condition
becomes true.

Do-loop until:

Syntax:

Do

Statement(s)

Loop until condition

Here statement(s) executes first and then the condition is


evaluated. If the condition is false then it executes
statements again. After executing the statements, the
condition is evaluated once again. And this process goes on
until condition becomes true.
Program to show the use of check box, radio
buttons and frames

Private Sub Check1_Click()

If Check1.Value = 1 Then

Text1.FontBold = True

Else

Text1.FontBold = False

End If

End Sub

Private Sub Check2_Click()

If Check2.Value = 1 Then

Text1.FontItalic = True

Else

Text1.FontItalic = False

End If

End Sub

Private Sub Check3_Click()


If Check3.Value = 1 Then

Text1.FontUnderline = True

Else

Text1.FontUnderline = False

End If

End Sub

Private Sub Check4_Click()

If Check4.Value = 1 Then

Text1.FontStrikethru = True

Else

Text1.FontStrikethru = False

End If

End Sub

Private Sub Command1_Click()

Text1.Text = ""

End Sub
Private Sub Command2_Click()

MsgBox "Do you want to Exit"

End

End Sub

Private Sub Option1_Click()

If Option1.Value = True Then

Text1.ForeColor = RGB(255, 0, 0)

Else

Text1.ForeColor = RGB(0, 0, 0)

End If

End Sub

Private Sub Option2_Click()

If Option1.Value = True Then

Text1.ForeColor = RGB(0, 255, 0)

Else

Text1.ForeColor = RGB(0, 0, 0)

End If
End Sub

Private Sub Option3_Click()

If Option1.Value = True Then

Text1.ForeColor = RGB(0, 0, 255)

Else

Text1.ForeColor = RGB(0, 0, 0)

End If

End Sub

Output:-
Program to display grade using switch case

Private Sub Command1_Click()

Dim marks As Integer

Dim grade As String

marks = Val(Text1.Text)

Select Case marks

Case 80 To 100

grade = "A"

Case 60 To 79

grade = "B"

Case 50 To 59

grade = "C"

Case 40 To 49

grade = "D"

Case 0 To 39

grade = "E"

End Select

MsgBox ("Grade is " & grade)


End Sub

Private Sub Command2_Click()

MsgBox ("Do you want to exit")

End

End Sub
Program to find greatest number between three numbers

Private Sub Command1_Click()

If CSng(Text1.Text) > CSng(Text2.Text) And


CSng(Text1.Text) > CSng(Text3.Text) Then

MsgBox "A is Greater"

ElseIf CSng(Text2.Text) > CSng(Text1.Text) And


CSng(Text2.Text) > CSng(Text3.Text) Then

MsgBox "B is Gretest"

ElseIf CSng(Text1.Text) = CSng(Text2.Text) Or


CSng(Text1.Text) = CSng(Text3.Text) Or
CSng(Text2.Text) = CSng(Text3.Text) Then

MsgBox "All Numbers are Same."

Else

MsgBox "C is Greatest"

End If

End Sub

Private Sub Command2_Click()

Text1.Text = ""

Text2.Text = ""
Text3.Text = ""

End Sub

Private Sub Command3_Click()

MsgBox "Do you Want To Exit"

End

End Sub

Private Sub Label1_Click()

End Sub

Private Sub Text1_Change()

End Sub

Private Sub Text2_Change()

End Sub

Private Sub Text3_Change()

End Sub
Output:-
Program to show the use of drive box, directory box,
file box.

Private Sub Command1_Click()

End

End Sub

Private Sub Dir1_Change()

File1.Path = Dir1.Path

End Sub

Private Sub Drive1_Change()

Dir1.Path = Drive1.Path

End Sub

Private Sub File1_Click()

Dim y As String

y = File1.Path & "\" & File1.FileName

End Sub
Private Sub Image1_Click()

Image1.Picture = LoadPicture(y)

End Sub
Program of Stopwatch using Timer

Private Sub cmdexit_Click()

End

End Sub

Private Sub cmdset_Click()

Timer1.Enabled = False

ss.Caption = "00"

mm.Caption = "00"

hh.Caption = "00"

End Sub

Private Sub cmdstart_Click()

If Timer1.Enabled = False Then

Timer1.Enabled = True

End If

End Sub
Private Sub cmdstop_Click()

Timer1.Enabled = False

End Sub

Private Sub Form_Load()

End Sub

Private Sub hh_Click()

End Sub

Private Sub ss_Click()

End Sub

Private Sub Timer1_Timer()

ss.Caption = Val(ss.Caption) + Val(1)

If ss.Caption = 60 Then

mm.Caption = Val(mm.Caption) + Val(1)

ss.Caption = 0

ElseIf mm.Caption = 60 Then


hh.Caption = Val(hh.Caption) + Val(1)

mm.Caption = 0

End If

End Sub
Program to draw Different Shapes

Private Sub Command1_Click()

Shape1.Visible = False

Line1.Visible = True

Line1.BorderStyle = 1

End Sub

Private Sub Command2_Click()

Line1.Visible = False

Shape1.Visible = True

Shape1.Shape = 3

End Sub

Private Sub Command3_Click()

Line1.Visible = False

Shape1.Visible = True

Shape1.Shape = 1

End Sub
Private Sub Command4_Click()

Line1.Visible = False

Shape1.Visible = True

Shape1.Shape = 2

End Sub
Program to design a Simple Calculator

Dim op1 As Double

Dim op2 As Double

Dim operator As String

Dim result As Double

Private Sub cmd1_Click(Index As Integer)

Text1.Text = Text1.Text & cmd1(Index).Caption

op1 = Val(Text1.Text)

End Sub

Private Sub cmdC_Click()

op2 = 0

op1 = 0

Text1.Text = ""

End Sub

Private Sub cmdce_Click()

op1 = 0

Text1.Text = ""

End Sub

Private Sub cmdequal_Click()


Select Case operator

Case "+"

result = op2 + op1

tetx1.Text = result

Case "-"

result = op2 - op1

tetx1.Text = result

Case "*"

result = op2 * op1

tetx1.Text = result

Case "/"

result = op2 / op1

tetx1.Text = result

End Select

op1 = result

End Sub

Private Sub Command1_Click(Index As Integer)

Text1.Text = ""

op2 = op1
op1 = 0

operator = Command1(Index).Caption

End Sub

Private Sub Command2_Click()

End

End Sub

Output:-
A
Practical File
On
Visual Basic

Submitted To:- Submitted By:-

Ms. XXXXX XXXXX

A.P. of Computer Science BCA-Final Yr.

Roll No:

JCD Memorial College Sirsa

You might also like