0% found this document useful (0 votes)
50 views63 pages

Bca3rd Year

The document contains a practical file of Visual Basic programs. It includes programs for logging in, cut copy paste, font styles, calculator, finding mean, displaying pictures using picturebox, finding sum using inputbox, creating a list using listbox, traffic lights using timer, shapes using shape control, changing color using scrollbar, drives and directories using file control, calculating HRA using if else, checking even or odd using if else.

Uploaded by

NARENDER
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views63 pages

Bca3rd Year

The document contains a practical file of Visual Basic programs. It includes programs for logging in, cut copy paste, font styles, calculator, finding mean, displaying pictures using picturebox, finding sum using inputbox, creating a list using listbox, traffic lights using timer, shapes using shape control, changing color using scrollbar, drives and directories using file control, calculating HRA using if else, checking even or odd using if else.

Uploaded by

NARENDER
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

PRACTICAL FILE

OF

VISUAL BASIC

SUBMITTED TO: SUBMITTED BY:


MRS. SAROJ SHARMA Kajal JADAV
LECT. IN CS DEPTT. BCA 3RD YEAR
ROLL NO.
Sr. No. Program Name Page No. Remarks

1. Program for Logging Form.

2. Program for creating options Cut, Copy, Paste.

3. Program for creating options Bold, Italic,


underline entered Text.
4. Program for calculating Total Average.

5. Program for creating Simple Calculator.

6. Program for calculating Mean.

7. Program for Displaying Picture Using Option


Button and Picture Box.
8. Program for calculating Sum Using Input Box
Control.
9. Program for creating List Using List Box Control.

10. Program for creating Traffic Signal Using Timer


Control.
11. Program for Displaying Shape Using Shape
Control.
12. Program for Changing Color of a Text Box as
Changing Scroll Bar Value.
13. Program for using Drive, Directory Using File
Control.
14. Program for HRA Using If Else Condition.

15. Program for Even Odd Using If Else Condition.

16. Program for sum of Natural Number using DO


WHILE _Loop, DO_LOOP WHILE.
17. Program for Call By Value and Call By Reference
By Using Function.
18. Program for generate Fibonacci Series.

19. Program for Sum of Two Matrix.

20. Program for creating Menus Using Menu Editor.

21. Program for creating Restaurant Application.

22. Program Using Built-In-Functions.


23. Program for Passing an Array to a Procedure.
24. Program for Function Returning Array.

25. Program for creating Pop Up Menu.

1.Program for logging.


Coding:-
Private Sub exit_Click()
End
End Sub
Private Sub login_Click()
If Text2.Text = "sonal jain" Then
MsgBox ("Password,OK")
listcombo.Show
Else
MsgBox ("Invalid password, Try Again")
End If
End Sub

Output:-
2.Program for cut, copy, paste, seltext, sellen, selstart.

Coding:-
Dim data As String
Private Sub clear_Click()
Text2.Text = " "
End Sub

Private Sub copy_Click()


data = Text1.Text
End Sub

Private Sub cut_Click()


data = Text1.Text
Text1.Text = ""
End Sub

Private Sub exit_Click()


End
End Sub

Private Sub paste_Click()


Text2.Text = data
End Sub

Private Sub sellen_Click()


Text2.Text = Text1.SelLength
End Sub

Private Sub selstart_Click()


Text2.Text = Text1.selstart
End Sub

Private Sub seltxt_Click()


Text2.Text = Text1.SelText
End Sub

Output:-

3.Program for font styles.


Coding:-
Private Sub Allcaps_Click()
If Allcaps.Value = 1 Then
Text1.Text = UCase(Text1.Text)
End If
End Sub

Private Sub Bold_Click()


If bold.Value = 1 Then
Text1.Font.bold = True
Else
Text1.Font.bold = False
End If
End Sub

Private Sub close_Click()


End
End Sub
Private Sub italic_Click()
If italic.Value = 1 Then
Text1.Font.italic = True
Else
Text1.Font.italic = False
End If
End Sub

Private Sub Smallcaps_Click()


If smallcaps.Value = 1 Then
Text1.Text = LCase(Text1.Text)
End If
End Sub

Private Sub strike_Click()


If strike.Value = 1 Then
Text1.Font.Strikethrough = True
Else
Text1.Font.Strikethrough = False
End If
End Sub

Private Sub Underline_Click()


If underline.Value = 1 Then
Text1.Font.underline = True
Else
Text1.Font.underline = False
End If
End Sub

Output:-
4. Program for total average.
Coding:-
Private Sub exit_Click()
End
End Sub

Private Sub grade_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 percentage_Click()


Text5.Text = Val(Text4.Text) / 3
End Sub

Private Sub total_Click()


Text4.Text = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)
End Sub

Output:-

5.Program for calculator.


Coding:-
Private Sub Command1_Click()
Dim num1 As Integer
Dim num2 As Integer
Dim sum As Integer
num1 = Val(Text1.Text)
num2 = Val(Text2.Text)
sum = num1 + num2
Text3.Text = sum
End Sub

Private Sub Command2_Click()


Dim num1 As Integer
Dim num2 As Integer
Dim mul As Integer
num1 = Val(Text1.Text)
num2 = Val(Text2.Text)
mul = num1 * num2
Text3.Text = mul
End Sub
Private Sub Command3_Click()
Dim num1 As Integer
Dim num2 As Integer
Dim subs As Integer
num1 = Val(Text1.Text)
num2 = Val(Text2.Text)
subs = num1 - num2
Text3.Text = subs
End Sub

Private Sub Command4_Click()


Dim num1 As Integer
Dim num2 As Integer
Dim div As Integer
num1 = Val(Text1.Text)
num2 = Val(Text2.Text)
div = num1 / num2
Text3.Text = div
End Sub

Private Sub Command5_Click()


Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub

Private Sub Command6_Click()


End
End Sub
Output:-

6. Program for find mean.


Coding:-
Private Sub Command1_Click()
Dim n As Integer
Dim num(1 To 20) As Double
Dim sum As Double
Dim i As Integer

n = Val(InputBox("ENTER TOTAL NUMBERS"))


Print
Print "TOTAL NUMBERS ARE" & n
Print

sum = 0
For i = 1 To n
num(i) = Val(InputBox("ENTER NUMBER" & i))
sum = sum + num(i)
Print "NUMBER" & i & "IS" & num(i)
Next
mean = sum / n

Print
Print "AVERAGE IS" & mean
End Sub

Private Sub Command2_Click()


End
End Sub

Output:-
7.program for picturebox.

Coding:-
Private Sub animal_Click()

Picture1.Picture = LoadPicture("C:\Users\Public\Pictures\Sample Pictures\


Penguins.jpg")

End Sub

Private Sub DESERT_Click()

Picture1.Picture = LoadPicture("C:\Users\Public\Pictures\Sample Pictures\


Desert.jpg")

End Sub

Private Sub exit_Click()

End

End Sub

Private Sub FLOWER_Click()


Picture1.Picture = LoadPicture("C:\Users\Public\Pictures\Sample Pictures\
Hydrangeas.jpg")

End Sub

Private Sub Picture1_Click()

End

End Sub

Output:-

8. Program for find sum of two numbers using input box method.
Coding:-
Private Sub close_Click()
End
End Sub

Private Sub sum_Click()


Dim n1 As Integer
Dim n2 As Integer
Dim sum As Double
n1 = InputBox("enter number")
n2 = InputBox("enter number")

sum = (n1 + n2)

MsgBox (" sum is: " & sum)


End Sub

Output:-
9. Program for list box.
Coding:-
Private Sub Command1_Click()
List1.AddItem Text1.Text
End Sub

Private Sub Command2_Click()


List1.RemoveItem List1.ListIndex
End Sub

Private Sub Command3_Click()


Text1.Text = ""
End Sub

Private Sub Command4_Click()


End
End Sub
Output:-

10. Program for traffic lights.


Coding:-
Private Sub exit_Click()
End
End Sub

Private Sub Timer1_Timer()


If Shape1.Visible Then
Command1.Caption = "stop"
Shape3.Visible = False
Shape1.Visible = True
Shape2.Visible = False

ElseIf Shape2.Visible Then


Command1.Caption = "ready"
Shape3.Visible = False
Shape1.Visible = False
Shape2.Visible = True

ElseIf Shape3.Visible Then


Command1.Caption = "go"
Shape3.Visible = False
Shape1.Visible = False
Shape2.Visible = True
End If
End Sub

Output:-

11. Program for shape control.


Coding:-
Private Sub circle_Click()

Line1.Visible = False
Shape1.Visible = True
Shape1.shape = 3
End Sub

Private Sub close_Click()


End
End Sub

Private Sub line_Click()


Shape1.Visible = False
Line1.Visible = True
Line1.BorderStyle = 1
End Sub
Private Sub oval_Click()
Line1.Visible = False
Shape1.Visible = True
Shape1.shape = 2
End Sub

Private Sub square_Click()


Line1.Visible = False
Shape1.Visible = True
Shape1.shape = 1
End Sub

Output:-
12. Program for scroll bar.

Coding:-
Private Sub exit_Click()
End
End Sub

Private Sub HScroll1_Change()


Text1.BackColor = HScroll1.Value
End Sub

Private Sub VScroll1_Change()


Text2.ForeColor = VScroll1.Value
End Sub
Output:-
13.Program for drive.

Coding:-
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()


Dir1.Path = Drive1.drive
End SUB

Private Sub File1_Click()


Dim a As String
a = Dir1.Path + "\" + File1.FileName
Text1.Text = a
End Sub
Output:-
14. Program for calculate hra.

Coding:-
Private Sub exit_Click(Index As Integer)
End
End Sub

Private Sub find_Click()


Dim basic As Integer
Dim hra As Integer
basic = Val(Text1.Text)
If basic <= 2000 Then
hra = 200
ElseIf basic <= 4000 Then
hra = 350
Else
hra = 500
End If
MsgBox ("hra is" & hra)
End Sub
Output:-
15. Program for find number is even or odd.

Coding:-
Private Sub Command1_Click()
Dim number As Double
number = InputBox("enetr any number that you want to check either even or odd")
evenodd (number)
End Sub

Public Sub evenodd(a As Double)


If a Mod 2 = 0 Then
MsgBox ("number is even")
Else
MsgBox ("number is odd")
End If
End Sub

Private Sub exit_Click()


End
End Sub
Output:-
16. Program for looping.

Coding:-
Dim x As Integer
Dim sum As Integer
Private Sub Command1_Click()
x=0
sum = 0
Do While x < 10
x=x+1
sum = sum + x
Loop
Print "SUM OF TEN NUMBERS USING DO WHILE LOOP" & sum
End Sub

Private Sub Command2_Click()


sum = 0
Do
x = x+ 1
sum = sum + x
Loop While x < 10
Print "SUM OF TEN NUMBERS USING DO LOOP WHILE" & sum
End Sub

Private Sub Command5_Click()


End
End Sub

OUTPUT:-
17. Program for call by value and call by reference.

Coding:-
Private Sub Command1_Click()
Dim var As Integer
var = InputBox("enter value")
Print "AFTER APPLYING CALL BY VALUE FUNCTION:-"
Print
Print var
twice (var)
Print var
End Sub
Function twice(ByVal num As Integer)
num = 2 * num
Print num
End Function

Private Sub Command2_Click()


End
End Sub

Private Sub Command3_Click()


Dim var As Integer
var = InputBox("enter value")
Print
Print "AFTER APPLYING CALL BY REFERENCE:-"
Print
Print var
Call dble(var)
Print var
End Sub
Function dble(ByRef num As Integer)
num = 2 * num
Print num
End Function

Output:-
18. Program for Fibonacci series.

Coding:-
Private Sub Command1_Click()
Dim first As Integer, second As Integer, number As Integer
If Text1.Text = "" Then
MsgBox ("enetr number")
Else
first = 0
second = 1
Print second
For i = 0 To (Val(Text1.Text) - 2)
number = first + second
Print number
first = second
second = number
Next i
End If
End Sub
Private Sub exit_Click()
End
End Sub

Output:-
19. Program for find sum of matrices.

Coding:-
Private Sub exit_Click()
End
End Sub

Public Sub sum_Click()


Dim a(1 To 5, 1 To 5) As Integer
Dim b(1 To 5, 1 To 5) As Integer
Dim sum(1 To 5, 1 To 5) As Integer
Dim i As Integer
Dim j As Integer
Dim m As String
Dim n As String
m = Val(InputBox("enter total number of rows:"))
n = Val(InputBox("enter total number of columns:"))
Print ("order of matrix is:" & m & " " & n)
Print
Print "enter first matrix:"
For i = 1 To m
For j = 1 To n
a(i, j) = Val(InputBox("enter rows elements:" & i & " " & j))
Print a(i, j)
Next
Print
Next
Print

Print "enter second matrix:"


For i = 1 To m
For j = 1 To n
b(i, j) = Val(InputBox("enter rows elements:" & i & " " & j))
Print b(i, j)
Next
Print
Next
Print

For i = 1 To m
For j = 1 To n
sum(i, j) = a(i, j) + b(i, j)
Next
Next
Print
Print "sum of matrices is:"
For i = 1 To m
For j = 1 To n
Print sum(i, j)
Next
Print
Next
End Sub
Output:-
20. Program for menu editor.

Coding:-
Private Sub exit_Click()
End
End Sub

Private Sub MNUCOPY_Click()


MsgBox ("code for copy option")
End Sub

Private Sub MNUCUT_Click()


MsgBox ("code for cut option")
End Sub

Private Sub MNUNEW_Click()


MsgBox ("code for new option")
End Sub

Private Sub MNUOPEN_Click()


MsgBox ("code for open any file")
End Sub

Private Sub MNUSAVE_Click()


MsgBox ("code for save option")
End Sub
Output:-
21. Program for restaurant.

Coding:-
Private Sub exit_Click()
End
End Sub

Private Sub Form_Load()


option1.Value = False
option2.Value = False
option3.Value = False
End Sub

Private Sub option1_Click()


If option1.Value = True Then
chineese.Show
indian.Hide
southindian.Hide
End If
End Sub

Private Sub option2_Click()


If option2.Value = True Then
chineese.Hide
indian.Show
southindian.Hide
End If
End Sub

Private Sub option3_Click()


If option3.Value = True Then
chineese.Hide
indian.Hide
southindian.Show
End If
End Sub

Coding:-
Dim a, b, c, d As Double
Private Sub back_Click()
restaurant.Show
End Sub

Private Sub clear_Click()


Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
Text5.Text = " "
Text6.Text = " "
Text7.Text = " "
End Sub

Private Sub total_Click()


If Check1.Value = 1 Then
a = Label9.Caption
b = Text1.Text
c=a*b
Text4.Text = c
End If
If Check2.Value = 1 Then
a = Label10.Caption
b = Text2.Text
c=a*b
Text5.Text = c
End If
If Check3.Value = 1 Then
a = Label11.Caption
b = Text3.Text
c=a*b
Text6.Text = c
End If
d = Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text)
Text7.Text = d
End Sub
Coding:-
Dim a, b, c, d As Double

Private Sub back_Click()


restaurant.Show
End Sub

Private Sub clear_Click()


Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
Text5.Text = " "
Text6.Text = " "
Text7.Text = " "
End Sub

Private Sub total_Click()


If Check1.Value = 1 Then
a = Label6.Caption
b = Text1.Text
c=a*b
Text4.Text = c
End If
If Check2.Value = 1 Then
a = Label7.Caption
b = Text2.Text
c=a*b
Text5.Text = c
End If
If Check3.Value = 1 Then
a = Label8.Caption
b = Text3.Text
c=a*b
Text6.Text = c
End If
d = Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text)
Text7.Text = d
End Sub
Coding:-
Dim a, b, c, d As Double

Private Sub back_Click()


restaurant.Show
End Sub

Private Sub clear_Click()


Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
Text5.Text = " "
Text6.Text = " "
Text7.Text = " "
End Sub

Private Sub total_Click()


If Check1.Value = 1 Then
a = Label6.Caption
b = Text1.Text
c=a*b
Text4.Text = c
End If
If Check2.Value = 1 Then
a = Label7.Caption
b = Text2.Text
c=a*b
Text5.Text = c
End If
If Check3.Value = 1 Then
a = Label8.Caption
b = Text3.Text
c=a*b
Text6.Text = c
End If
d = Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text)
Text7.Text = d
End Sub

OUTPUT:-
22. program for built in function.

Coding:-
Private Sub Command1_Click()
Dim x, a As Integer
a = InputBox("enter number")
Print "the value of a is:"; a
Print
Print
Print "square root of a is:" & Sqr(a)
Print
Print
Print "absolute value of a is:" & Abs(-20)
Print
Print
End Sub
Output:-
23.program for passing an array to procedure.

Coding:-
Private Sub exit_Click()
End
End Sub

Private Sub passanarray_Click()


Dim a(2) As Single
a(0) = 5
a(1) = 6
a(2) = 7
Call takearray(a)
End Sub
Private Sub takearray(x() As Single)
Dim element As Variant
For Each element In x
Print element
Next
End Sub
Output:-
24.Program for function returning array.

Coding:-
Public Function RArray() As Variant
Dim a(2) As Integer
a(0) = 1
a(1) = 2
a(2) = 3
RArray = a
End Function

Private Sub exit_Click()


End
End Sub

Private Sub returnanarray_Click()


Dim returnval As Variant
Dim element As Variant
returnval = RArray
For Each element In returnval
Print element
Next
End Sub

Output:-
25. Program for Pop Up Menu.
Coding:-
Private Sub Form_mousedown(button As Integer, shift As Integer, x As Single, y As
Single)
If button = vbRightButton Then
popupmenu mnuformatpopup
End If
End Sub

Output:-

You might also like