SlideShare a Scribd company logo
1 of 45
Download to read offline
Studocu is not sponsored or endorsed by any college or university
Vb-practical-file - VB complete notes for practical
Computer science (Kurukshetra University)
Studocu is not sponsored or endorsed by any college or university
Vb-practical-file - VB complete notes for practical
Computer science (Kurukshetra University)
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
LAB MANUAL FOR PRACTICAL
COURSES
MSc Computer Science 2nd
year
Practical File of
Visual Basic (CS-DE-27)
DIRECTORATE OF DISTANC EDUCATION
KURUKSHETRA UNIVERSITY, KURUKSHETRA.
HARYANA- 136119
PRACTICAL EXAMINATION -
Name- Mohit Roll No.-
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
EDUCATION DIRECTORATE OF DISTANCE
(Established by the State Legislature Act XII of 1956)
KURUKSHETRA UNIVERSITY,
KURUKSHETRA
Department of Computer Science
This is to certify that this is the bonafide record work of practical
work done by
Mr. MOHIT Reg.No. 22248593 Roll No.
Of MSc Computer Science 2nd
year ,Of Subject CS-DE-27
(Visual Basic), at the Directorate of Distance
Education, Kurukshetra University, Kurukshetra during
the academic year.
July 2022 - 2023 .
Internal Examiner External Examiner
Name- Mohit Roll No.-
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Visual Basic (CS-DE- 27) Software Lab – II
CONTENTS
Sl.
No.
Title of the Exercise Page No.
1. Print the Sentence 04
2. String Concatenation 05
3. Vowel or Not 06
4. String Conversion 07
5. Simple Calculator 08
6. Online Examination 12
7. Loading of Control 14
8. Dynamic Menus 17
9. Analog Clock 19
10. Picture Viewer 23
11. Tic-Tac-Toe 27
12. Drag-Drop Recycle Bin 30
13. Traffic Light 32
14. Plotter 36
15. GP( Geometric Progression) 38
16. A Smart Audio Player 41
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Excercise Number - 1: Print the sentence
Aim:
To write a program to print the sentence "Write First program in Visual basic"
Algorithm:
1. Start the application
2. To create a module
3. To declare the variable string as dimension
4. Assign any sentence to the variable as str
5. To display the sentence
6. End the Module
7. Deploy and run the program
Source Code:
Module Module1
Sub Main()
Dim str As String
str = "Write First program in Visual basic"
Console.WriteLine(str)
Console.ReadLine()
End Sub
End Module
Output:
Write First Program in Visual basic
Result:
Thus the program was executed and its output was verified.
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Excercise Number - 2: String Concatenation
Aim:
To write a program to concatenate any two or more strings in Visual basic.
Algorithm:
1. Start the application
2. To create a module and declare the variable string as dimension
3. Assign any word to each of the variables
4. To concatenate all the words and print them
5. End the module
6. Deploy and run the program
Source Code:
Module Module1
Sub Main()
Dim str1, str2, str3 As
String str1 = "Visual"
str2 = "Basic"
str3 = "Program"
Console.WriteLine(str1 + " " + str2 + " " + str3)
Console.ReadLine()
End Sub
End Module
Output:
Visual basic program
Result:
Thus the program was executed and its output was verified.
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Excercise Number - 3: Vowel or not
Aim:
To write a program to check whether a character is vowel or not.
Algorithm:
1. Start the application and create and design a form with needed buttons
2. Click the button to write the program in editor page
3. To declare the variable as string
4. To create textbox and assign the textbox values as variable
5. If the textbox values as vowel then the message box displays “The Given String is
vowel”
6. Otherwise the messagebox displays “The Given String is not vowel”
7. Deploy and run the program
Source Code:
Public Class Vowels
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim c As String
c = TextBox1.Text
If c = "a" Or c = "A" Or c = "e" Or c = "E" Or c = "i" Or c = "I" Or c = "o" Or c =
"O" Or c = "u" Or c = "U" Then
MsgBox("The Given String is
vowel") Else
MsgBox("The Given String is not
vowel") End If
End Sub
End Class
Output:
Result:
Thus the program was executed and its output was verified.
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Excercise Number - 4: String Conversion
Aim:
To write a program to accept character for console and check the case of the character.
Algorithm:
1. Start the application
2. Open a new file and design the form with needed such controls as labelbox,
textbox,button.
3. Click the button to write the program in editor page
4. Check the string is lower or upper case
5. Deploy and run the program
Source Code:
Public Class Conversion
Private Sub Low_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Low.Click
TextBox2.Text = TextBox1.Text.ToLower
End Sub
Private Sub Upp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Upp.Click
TextBox2.Text = TextBox1.Text.ToUpper
End Sub
End Class
Output:
Result:
Thus the program was executed and its output was verified.
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Excercise Number - 5: Simple Calculator
Aim:
To write a program to develop a simple calculator for an arithmetic operations
Algorithm:
1. Start the application
2. Open a new file and design the form with needed such controls as labelbox,
textbox,button.
3. Click the button to write the program in editor page
4. Click the +,-,*,/ operator to prefer their respective operations
5. Use if else condition to do all the operations of arithmetic calculations
6. Deploy and run the program
Source code:
Public Class Form1
Dim frstnum As Decimal
Dim scndnum As Decimal
Dim operations As Integer
Dim operator_selector As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "2"
Else
TextBox1.Text = "2"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "3"
Else
TextBox1.Text = "3"
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
If TextBox1.Text <> "0" Then
TextBox1.Text += "4"
Else
TextBox1.Text = "4"
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "5"
Else
TextBox1.Text = "5"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "6"
Else
TextBox1.Text = "6"
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "7"
Else
TextBox1.Text = "7"
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "8"
Else
TextBox1.Text = "8"
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "9"
Else
TextBox1.Text = "9"
End If
End Sub
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "0"
End If
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button11.Click
frstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
operations = 1 '=+
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button12.Click
frstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
operations = 2 '=-
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click
frstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
operations = 3 '=*
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button14.Click
frstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
operations = 4 '=/
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button16.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button15.Click
TextBox1.Text = "0"
End Sub
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button17.Click
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
If operator_selector = True Then
scndnum = TextBox1.Text
If operations = 1 Then
TextBox1.Text = frstnum + scndnum
ElseIf operations = 2 Then
TextBox1.Text = frstnum - scndnum
ElseIf operations = 3 Then
TextBox1.Text = frstnum * scndnum
ElseIfscndnum = 0 Then
TextBox1.Text = "Error!"
Else
TextBox1.Text = frstnum / scndnum
End If
operator_selector = False
End If
End Sub
End Class
Output:
Result:
Thus the program was executed and its output was verified.
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Excercise Number - 6: Online Examination
Aim:
To write a program to create Online Examination Using Timer.
Algorithm:
1. Start the application
2. Open a new file and design the form with needed such controls as labelbox,
textbox,button.
3. Click the button to write the editor page
4. Set a Timer as an interval = 1000 seconds
5. To declare all the variables
6. Radio button is used for the answer selection in the online exam
7. Use the message box to display the result
8. Deploy and run the program
Source Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Label3.Text = 20
Timer1.Enabled = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label3.Visible = False
Dim total As Integer
total = 0
If RadioButton1.Checked = True Then
total += 1
End If
If RadioButton3.Checked = True Then
total += 1
End If
MsgBox("Your Mark is " & total)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If Label3.Text = 0 Then
Timer1.Enabled = False
MsgBox("Timeout")
Else
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Label3.Text = Label3.Text
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
End ClassPublic Class Form1
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Label3.Text =
20
Timer1.Enabl
ed = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Label3.Visib
le = False
Dim total As
Integer total
= 0
If RadioButton1.Checked =
True Then total += 1
End If
If RadioButton3.Checked =
True Then total += 1
End If
MsgBox("Your Mark is
" & total) End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Timer1.Tick
If Label3.Text
= 0 Then
Timer1.Enabl
ed = False
MsgBox("Tim
eout") Else
Label3.Text =
Label3.Text - 1 End
Output:
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Practical – 7
LOADING CONTROLS AT RUNTIME: Write a program which demonstrates the loading of
controls at runtime.
Dim i As Integer
Dim lblindex As Integer
Dim btnindex As Integer
Private Sub cmd_btn_Click(Index As Integer)
' first give the index =0 to command button at design time
Load cmd_btn(btnindex)
With cmd_btn(btnindex)
.Caption = "Button " & btnindex
.Left = 3800
.Top = 1200 + btnindex * 500
.Height = 300
.Visible = True
End With
btnindex = btnindex + 1
End Sub
Private Sub cmd_lbl_Click()
Set lblnew = Controls.Add("VB.Label", "Labels" & lblindex)
With lblnew
.Caption = "Label " & lblindex
.Left = 800
.Top = 1200 + lblindex * 500
.Visible = True
End With
lblindex = lblindex + 1
End Sub
Private Sub cmd_Remove_Button_Click()
If btnindex > 1 Then
btnindex = btnindex - 1
Unload cmd_btn(btnindex)
Else
MsgBox ("There is no Button to remove")
End If
End Sub
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Private Sub cmd_remove_Label_Click()
If lblindex > 1 Then
lblindex = lblindex - 1
Me.Controls.Remove ("Labels" & lblindex)
Else
MsgBox ("There is no label to remove")
End If
End Sub
Private Sub cmd_Remove_Tbox_Click()
If i > 1 Then
i = i - 1
Me.Controls.Remove ("TextBox" & i)
Else
MsgBox ("There is no TextBox to remove")
End If
End Sub
Private Sub cmd_tbox_Click()
Set txtnew = Controls.Add("VB.TextBox", "TextBox" & i)
txtnew.Text = "TextBox " & i
' move left, top, width , height
txtnew.Move 2200, 1200 + i * 500, 1400, 20
txtnew.Visible = True
i = i + 1
End Sub
Private Sub Form_Load()
i = 1
btnindex = 1
lblindex = 1
End Sub
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Practical – 8
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
DYNAMIC MENUS: Write a program which demonstrates the dynamic menus. For example
the recently visited files are added in menus which changes dynamically.
Dim Index As Integer
Private Sub cmd_execute_Click()
If Index < 5 Then
Index = Index + 1
Load FileRecent(Index)
FileRecent(Index).Enabled = True
End If
Dim i As Integer
i = Index
Do While i > 1
FileRecent(i).Caption = FileRecent(i - 1).Caption
i = i - 1
Loop
FileRecent(1).Caption = tbox_command.Text
tbox_command.Text = ""
tbox_command.SetFocus
End Sub
Private Sub FileExit_Click()
End
End Sub
Private Sub FileRecent_Click(Index As Integer)
tbox_command.Text = FileRecent(Index).Caption
End Sub
Private Sub FileReset_Click()
For i = 1 To Index
Unload FileRecent(i)
Next
End Sub
Private Sub Form_Load()
FileRecent(0).Enabled = False
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
End Sub
Practical – 9
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
ANALOG CLOCK: Write a program to create an analog clock, which shows all the three
hands (Hour, Minute and second). You can add an option to change the background of the
clock.
Dim min, hour As Integer
Const PI = 3.14159265 'Pi constant
Dim theta As Single
Dim dtheta As Single
Dim second As Long
Dim cx As Single
Dim cy As Single
Dim radius As Single
Const stheta As Single = 4.7142857
Private Sub btn_image_Click()
CommonDialog1.Filter = "Graphics|*.bmp;*.gif;*.jpg|Text File|*.txt|All Files|*.*"
CommonDialog1.ShowOpen
If Not Picture1.AutoRedraw Then Picture1.AutoRedraw = True
Picture1.Picture = LoadPicture(CommonDialog1.Filename)
Picture1.PaintPicture Picture1.Picture, 0, 0, 5000, 5000
gettime
End Sub
Public Sub gettime()
theta = stheta
dtheta = 2 * PI / 60
cx = 2500
cy = 2500
radius = 2300
second = Format(Time, "s") + Format(Time, "n") * 60 + (Format(Time, "h") Mod 12) *
3600
min = second / 60
hour = Format(Time, "h") Mod 12
LineSec.X1 = 2500
LineSec.Y1 = 2500
theta = stheta + (second Mod 60) * dtheta
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
LineSec.x2 = cx + (radius - 100) * Cos(theta)
LineSec.y2 = cy + (radius - 100) * Sin(theta)
line_minute.X1 = 2500
line_minute.Y1 = 2500
line_Hour.X1 = 2500
line_Hour.Y1 = 2500
line_Hour.x2 = cx + (radius - 200) * Cos(stheta + (2 * PI / 3600) * min * 5)
line_Hour.y2 = cy + (radius - 200) * Sin(stheta + (2 * PI / 3600) * min * 5)
End Sub
Private Sub cmd_ForeColor_Click()
CommonDialog1.ShowColor
For i = 0 To Label14.Count - 1
Label14(i).ForeColor = CommonDialog1.color
Next i
Shape1.BorderColor = CommonDialog1.color
DrawCircle 2500, 2500, 2400, 60, CommonDialog1.color
End Sub
Private Sub Form_Load()
'LoadDots
DrawCircle 2500, 2500, 2400, 60
gettime
End Sub
Private Sub Timer2_Timer()
second = second + 1
theta = theta + dtheta
line_minute.x2 = cx + (radius - 100) * Cos(stheta + (2 * PI / 3600) * second)
line_minute.y2 = cy + (radius - 100) * Sin(stheta + (2 * PI / 3600) * second)
If second Mod 60 = 0 Then
theta = 4.7142857
min = min + 1
line_Hour.x2 = cx + (radius - 200) * Cos(stheta + (2 * PI / 3600) * min * 5)
line_Hour.y2 = cy + (radius - 200) * Sin(stheta + (2 * PI / 3600) * min * 5)
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
If second = 43200 Then second = 0
End If
If min = 720 Then
min = 0
End If
X = cx + radius * Cos(theta)
Y = cy + radius * Sin(theta)
LineSec.x2 = X
LineSec.y2 = Y
End Sub
Private Sub DrawCircle(ByVal cx As Single, ByVal cy As Single, ByVal radius As Single,
ByVal num_segments As Integer, Optional fcolor As ColorConstants)
Const PI = 3.14159265
Dim X As Single
Dim Y As Single
Dim theta As Single
Dim dtheta As Single
Dim second As Integer
For i = 1 To Dot.Count - 1
Unload Dot(i)
Next
dtheta = 2 * PI / num_segments
theta = stheta
For seg = 1 To num_segments
theta = theta + dtheta
X = cx + radius * Cos(theta)
Y = cy + radius * Sin(theta)
Load Dot(seg)
Dot(seg).X1 = X
Dot(seg).Y1 = Y
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Dot(seg).x2 = X + 2
Dot(seg).y2 = Y + 2
Dot(seg).BorderWidth = 3
If seg Mod 5 = 0 Then
Dot(seg).BorderWidth = 5
Else
Dot(seg).BorderColor = fcolor
End If
Dot(seg).Visible = True
Next seg
End Sub
Practical – 10
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
PICTURE VIEWER: Create a program that enables the users to open and choose files from
the folders in their PC. The picture viewer provides the functionality to move to the NEXT
and PREVIOUS photos, ZOOM IN & ZOOM OUT
Dim Index As Integer
Dim path As String
Dim X, Y As Integer
Private Sub bnt_prev_Click()
If Index > 0 Then
Index = Index - 1
End If
path = File1.path
If Right(path, Len(path) - 2) <> "" Then
path = path & ""
End If
PictureViewer.Picture1.Picture = LoadPicture(path & File1.List(Index))
PictureViewer.Picture1.PaintPicture PictureViewer.Picture1.Picture, 0, 0, 800, 600
End Sub
Private Sub btn_next_Click()
If Index < File1.ListCount - 1 Then
Index = Index + 1
path = File1.path
If Right(path, Len(path) - 2) <> "" Then
path = path & ""
End If
Picture1.Picture = LoadPicture(path & File1.List(Index))
Picture1.PaintPicture Picture1.Picture, 0, 0, 800, 600
Picture2.Picture = LoadPicture(path & File1.List(Index))
End If
End Sub
Private Sub btn_open_Click()
openFolderDialog.Show 1
End Sub
Private Sub btn_zoomin_Click()
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
If Picture1.Picture = 0 Then
Exit Sub
End If
X = X + 80
Y = Y + 60
Picture1.Height = Y
Picture1.Width = X
Picture1.PaintPicture Picture1.Picture, 0, 0, X, Y
If X > Pic_holder.ScaleWidth Then
HScroll1.Max = X - Pic_holder.ScaleWidth
VScroll1.Max = Y - Pic_holder.ScaleHeight
Else
HScroll1.Max = 0
VScroll1.Max = 0
End If
End Sub
Private Sub btn_zoomout_Click()
If Picture1.Picture = 0 Then
Exit Sub
End If
If X > 160 Then
X = X - 80
Y = Y - 60
End If
Picture1.Height = Y
Picture1.Width = X
Picture1.PaintPicture Picture1.Picture, 0, 0, X, Y
If Picture1.ScaleWidth - Pic_holder.ScaleWidth > 0 Then
HScroll1.Max = Picture1.ScaleWidth - Pic_holder.ScaleWidth
VScroll1.Max = Picture1.ScaleHeight - Pic_holder.ScaleHeight
Else
HScroll1.Max = 0
VScroll1.Max = 0
End If
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
End Sub
Private Sub Form_Load()
X = 800
Y = 600
'Set up picturebox
With Picture1
.ScaleMode = vbPixels
.AutoRedraw = True
.DrawMode = vbInvert
.DrawStyle = SelDrawType
.BackColor = vbWhite
.MousePointer = vbCrosshair
.Left = 0
.Top = 0
.ScaleHeight = Pic_holder.ScaleHeight
.ScaleWidth = Pic_holder.ScaleWidth
End With
Picture2.ScaleHeight = Picture1.ScaleHeight
Picture2.ScaleWidth = Picture1.ScaleWidth
HScroll1.Max = Picture1.ScaleWidth - Pic_holder.ScaleWidth
HScroll1.min = 0
VScroll1.Max = Picture1.ScaleHeight - Pic_holder.ScaleHeight
HScroll1.min = 0
End Sub
Private Sub HScroll1_Change()
Picture1.Left = -HScroll1.Value
End Sub
Private Sub VScroll1_Change()
Picture1.Top = -VScroll1.Value
End Sub
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Practical – 11
TIC- TAC- TOE: Develop a program Tic Tac Toe in VB so that you can play the game
virtually. First of all, you need to draw the interface with four straight lines, then insert nine
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
image controls and make them an array, Image1 (0) to Image1 (8). Secondly, insert two
pictures, one is a circle and the other one is a cross to represent player 1 and player2.
Dim sym As String
Dim winr(9) As String
Private Sub Form_Load()
sym = "X"
Dim i As Integer
For i = 0 To 8
winr(i) = i
Next i
End Sub
Private Sub Label1_Change()
If Label1.Caption = "Player 1" Then
sym = "X"
Else
sym = "0"
End If
End Sub
Private Sub lbl_gstatus_Click(Index As Integer)
If lbl_gstatus(Index).Caption = "" Then
lbl_gstatus(Index).Caption = sym
winr(Index) = sym
If Label1.Caption = "Player 1" Then
Label1.Caption = "Player 2"
Else
Label1.Caption = "Player 1"
End If
check
End If
End Sub
Function check()
Dim i As Integer
Dim won As Boolean
Dim psymbol As String
If winr(0) = winr(1) And winr(1) = winr(2) Then
won = True
psymbol = winr(0)
ElseIf winr(2) = winr(4) And winr(4) = winr(6) Then
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
won = True
psymbol = winr(2)
ElseIf winr(0) = winr(3) And winr(3) = winr(6) Then
won = True
psymbol = winr(0)
ElseIf winr(1) = winr(4) And winr(4) = winr(7) Then
won = True
psymbol = winr(1)
ElseIf winr(2) = winr(5) And winr(5) = winr(8) Then
won = True
psymbol = winr(2)
ElseIf winr(0) = winr(1) And winr(1) = winr(2) Then
won = True
psymbol = winr(0)
ElseIf winr(3) = winr(4) And winr(4) = winr(5) Then
won = True
psymbol = winr(3)
ElseIf winr(6) = winr(7) And winr(7) = winr(8) Then
won = True
psymbol = winr(6)
End If
If won = True Then
Dim pno As Integer
If psymbol = "X" Then
pno = 1
Else
pno = 2
End If
MsgBox (" Player " & pno & " won")
won = False
For i = 0 To 8
winr(i) = i
lbl_gstatus(i).Caption = ""
Label1.Caption = "Player 1"
Next
End If
End Function
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Practical – 12
A DRAG & DROP RECYCLE_BIN: Make a drag and drop program that resembles a recycle
bin. Drag and drop is a common windows application where you can drag and drop an object
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
such as a file into a folder or into a recycle bin. This capability can be easily programmed in
visual basic
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
Source.Visible = False
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As
Single)
If Button = vbRightButton Then
PopupMenu RestoreMenu, vbPopupMenuRightAlign
End If
End Sub
Private Sub Restore_Click()
Image1.Visible = True
Image2.Visible = True
Image3.Visible = True
Image4.Visible = True
End Sub
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Practical – 13
TRAFFIC LIGHT: Create a Traffic light program in which, one can insert one timer and sets
its interval according to its desire. Suppose set it to 3000, which is equivalent to 3 seconds.
Next you insert three shapes and set their shape properties to circle and fill the colors.
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Dim status(4) As Boolean
Const interval As Integer = 1000
Dim wait As Integer
Dim waittime(3) As Integer
Dim stage, t1, t2, t3, t4 As Integer
Private Sub Command1_Click()
Me.FillColor = vbRed
Me.FillStyle = vbSolid
Call light(250, 50, 1)
Call light(100, 200, 1)
Call light(400, 200, 1)
Call light(250, 300, 1)
waittime(0) = 10
waittime(1) = 4
waittime(2) = 8
Timer2.Enabled = True
Timer1.Enabled = True
t1 = waittime(0) + waittime(1)
t2 = (waittime(1) + waittime(2)) * 2 + 1
t3 = (waittime(1) + waittime(2)) * 3 + 1
t4 = (waittime(1) + waittime(2)) * 4 + 1
Label1.Left = 320
Label1.Top = 50
Label2.Left = 320
Label2.Top = 300
Label3.Left = 170
Label3.Top = 200
Label4.Left = 470
Label4.Top = 200
wait = 10
stage = 0
End Sub
Function light(X As Integer, Y As Integer, Optional c As Integer)
Call rectangle(X, Y, X + 50, Y + 100)
Call fillcircle(X + 25, Y + 20, vbWhite)
Call fillcircle(X + 25, Y + 50, vbWhite)
Call fillcircle(X + 25, Y + 80, vbWhite)
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Select Case c
Case 1:
Call fillcircle(X + 25, Y + 20, vbRed)
Case 2:
Call fillcircle(X + 25, Y + 50, vbYellow)
Case 3:
Call fillcircle(X + 25, Y + 80, vbGreen)
End Select
End Function
Function rectangle(X As Integer, Y As Integer, x2 As Integer, y2 As Integer)
Me.Line (X, Y)-(X, y2), vbRed
Me.Line (x2, Y)-(x2, y2), vbRed
Me.Line (X, Y)-(x2, Y), vbRed
Me.Line (X, y2)-(x2, y2), vbRed
End Function
Function fillcircle(X As Integer, Y As Integer, color As ColorConstants)
Me.FillColor = color
Me.Circle (X, Y), 10, vbBlack
End Function
Private Sub Timer1_Timer()
t1 = t1 - 1
t2 = t2 - 1
t3 = t3 - 1
t4 = t4 - 1
Label1.Caption = t1
Label2.Caption = t2
Label3.Caption = t3
Label4.Caption = t4
End Sub
Private Sub Timer2_Timer()
stage = stage + 1
Select Case stage
Case 1:
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Call light(250, 50, 2)
Timer2.interval = interval * waittime(1)
Case 2:
Call light(250, 50, 3)
Call light(400, 200, 1)
t1 = waittime(2)
Timer2.interval = interval * waittime(2)
Case 3:
Call light(250, 50, 2)
Call light(250, 300, 2)
t1 = (waittime(1) + waittime(2)) * 3 + waittime(1)
Timer2.interval = interval * waittime(1)
Case 4:
Call light(250, 50, 1)
Call light(250, 300, 3)
t2 = waittime(2)
Timer2.interval = interval * waittime(2)
Case 5:
Call light(100, 200, 2)
Call light(250, 300, 2)
t2 = (waittime(1) + waittime(2)) * 3 + waittime(1)
Timer2.interval = interval * waittime(1)
Case 6:
Call light(100, 200, 3)
Call light(250, 300, 1)
t3 = waittime(2)
Timer2.interval = interval * waittime(2)
Case 7:
Call light(100, 200, 2)
Call light(400, 200, 2)
t3 = (waittime(1) + waittime(2)) * 3 + waittime(1)
Timer2.interval = interval * waittime(1)
Case 8:
Call light(100, 200, 1)
Call light(400, 200, 3)
t4 = waittime(2)
Timer2.interval = interval * waittime(2)
Case 9:
Call light(250, 50, 2)
Call light(400, 200, 2)
t4 = (waittime(1) + waittime(2)) * 3 + waittime(1)
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Timer2.interval = interval * waittime(1)
stage = 1
End Select
End Sub
Practical – 14
CUBIC FUNCTION GRAPH PLOTTER: Make a program that enables users to input the
coefficients of a cubic equation and draw its graph. The cubic equation takes the form
ax3
+bx2
+cx+d.
Private Sub btn_cls_Click()
pic_graph.Cls
End Sub
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Private Sub cmd_draw_Click()
Dim a, b, c, d As Integer
Dim w, v As Double
a = Val(tbox_a.Text)
b = Val(tbox_b.Text)
c = Val(tbox_c.Text)
d = Val(tbox_d.Text)
'Using a scale of 0.5 cm to represent i unit to draw the graph
' Need to make some transformation as the coordinates in VB start from top left
For w = 0 To 10 Step 0.001
v = a * (5 - w) ^ 3 + b * (5 - w) ^ 2 + c * (5 - w) + d
pic_graph.PSet (w, 5 - v)
Next w
End Sub
Private Sub Form_Load()
Line_x.X1 = 0
Line_x.x2 = pic_graph.ScaleWidth
Line_x.Y1 = pic_graph.ScaleHeight / 2
Line_x.y2 = pic_graph.ScaleHeight / 2
Line_y.X1 = pic_graph.ScaleWidth / 2
Line_y.x2 = pic_graph.ScaleWidth / 2
Line_y.Y1 = 0
Line_y.y2 = pic_graph.ScaleHeight
End Sub
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Practical – 15
GEOMETRIC PROGRESSION: Make a Visual Basic program that can compute a
geometric progression and display the results in a list box.
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Private Sub btn_sum_Click()
Dim a, n As Integer
Dim r As Single
If check() = False Then
MsgBox ("Required fields are empty")
Exit Sub
End If
If opt_inputbox.Value Then
a = InputBox("First Term", "Geometric Progression", 1)
r = InputBox("Common Ratio", "Geometric Progression", 1)
n = InputBox("How many terms", "Geometric Progression", 1)
Else
a = tbox_fn.Text
r = tbox_r.Text
n = tbox_terms.Text
End If
Dim s As Single
If r > 1 Then
s = (a * ((r ^ n) - 1)) / (r - 1)
Else
s = (a * (1 - (r ^ n))) / (1 - r)
End If
MsgBox ("The sum is " & s)
End Sub
Private Sub btn_term_Click()
Dim a, n As Integer
Dim r As Single
If check() = False Then
MsgBox ("Required fields are empty")
Exit Sub
End If
If opt_inputbox.Value Then
a = InputBox("First Term", "Geometric Progression", 1)
r = InputBox("Common Ratio", "Geometric Progression", 1)
n = InputBox("Which Term you want to display", "Geometric Progression", 1)
Else
a = tbox_fn.Text
r = tbox_r.Text
n = tbox_terms.Text
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
End If
MsgBox ("The " & n & "th term is " & a * (r ^ (n - 1)))
End Sub
Private Sub cmd_Clear_Click()
List1.Clear
End Sub
Private Sub cmd_series_Click()
If check() = False Then
MsgBox ("Required fields are empty")
Exit Sub
End If
cmd_Clear_Click
Dim f, n, terms As Integer
Dim r As Single
f = tbox_fn.Text
r = tbox_r.Text
terms = tbox_terms.Text
List1.AddItem "Term" & vbTab & "Value"
List1.AddItem "-----------------------"
n = 1
Do
List1.AddItem n & vbTab & f * (r ^ (n - 1))
n = n + 1
Loop While n <= terms
End Sub
Function check() As Boolean
If tbox_fn.Text = "" Then
check = False
ElseIf tbox_r.Text = "" Then
check = False
ElseIf tbox_terms.Text = "" Then
check = False
Else
check = True
End If
End Function
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Practical – 16
A SMART AUDIO PLAYER: Write a program to create a player that enables you to play
midi and wave files in your hard drives or floppy A or CDROM. It should allow you to change
drives and search for the particular sound file that you wish to play. In this program, you have
to add a Combo box, a List Box, a Text Box, a Drive List Box, a command button you label as
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
"PLAY", another command button you label as "STOP", and one more command button you
label as "EXIT". You have to add in MMControl and make it invisible.
Dim i As Integer
Private Sub btn_exit_Click()
End
End Sub
Private Sub btn_Play_Click()
If File1.ListCount = 0 Then Exit Sub
Timer1.Enabled = True
Slider1.Value = 0
MMControl1.Command = "Close"
MMControl1.Filename = File1.path & "" & File1.List(i)
MMControl1.Command = "Open"
MMControl1.Command = "Play"
File1.Selected(i) = True
i = i + 1
If i >= File1.ListCount Then
i = 0
End If
End Sub
Private Sub btn_Stop_Click()
If btn_Stop.Caption = "Resume" Then
MMControl1.Command = "Play"
btn_Stop.Caption = "Pause"
Else
MMControl1.Command = "Pause"
btn_Stop.Caption = "Resume"
End If
End Sub
Private Sub cbox_pattern_Click()
If cbox_pattern.ListIndex = 0 Then
File1.Pattern = "*.wav;*.midi"
Else
File1.Pattern = "*.mp3;*.wav;*.mp4;*.mpeg;*.avi;*.dat"
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
End If
End Sub
Private Sub Dir1_Change()
File1.path = Dir1.path
End Sub
Private Sub Drive1_Change()
Dir1.path = Drive1.Drive
End Sub
Private Sub File1_Click()
i = File1.ListIndex
btn_Play_Click
End Sub
Private Sub Form_Load()
File1.Pattern = "*.midi;*.wav"
MMControl1.PlayEnabled = True
MMControl1.AutoEnable = True
End Sub
Private Sub Timer1_Timer()
Slider1.Value = Round(MMControl1.Position / MMControl1.Length * 100)
End Sub
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983
Name- Mohit Roll No. -
Downloaded by BALWAN SAINI (sainibalwan86@gmail.com)
lOMoARcPSD|28417983

More Related Content

Similar to VISUAL BASIC PRATICAL FILE MSC COMPUTER SCIENCE.pdf

Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
Aarti P
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
AASTHA76
 
Cis 170 c ilab 5 of 7 arrays and strings
Cis 170 c ilab 5 of 7 arrays and stringsCis 170 c ilab 5 of 7 arrays and strings
Cis 170 c ilab 5 of 7 arrays and strings
CIS321
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
ccis224477
 

Similar to VISUAL BASIC PRATICAL FILE MSC COMPUTER SCIENCE.pdf (20)

Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
 
Cis 170 c ilab 5 of 7 arrays and strings
Cis 170 c ilab 5 of 7 arrays and stringsCis 170 c ilab 5 of 7 arrays and strings
Cis 170 c ilab 5 of 7 arrays and strings
 
06 win forms
06 win forms06 win forms
06 win forms
 
Vb (1)
Vb (1)Vb (1)
Vb (1)
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdf
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
C++ loop
C++ loop C++ loop
C++ loop
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Cara membuat software dj
Cara membuat software djCara membuat software dj
Cara membuat software dj
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
Visual studio.net
Visual studio.netVisual studio.net
Visual studio.net
 
SPF WinForm Programs
SPF WinForm ProgramsSPF WinForm Programs
SPF WinForm Programs
 
Vb.net iv
Vb.net ivVb.net iv
Vb.net iv
 
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
 

Recently uploaded

Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 

VISUAL BASIC PRATICAL FILE MSC COMPUTER SCIENCE.pdf

  • 1. Studocu is not sponsored or endorsed by any college or university Vb-practical-file - VB complete notes for practical Computer science (Kurukshetra University) Studocu is not sponsored or endorsed by any college or university Vb-practical-file - VB complete notes for practical Computer science (Kurukshetra University) Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 2. LAB MANUAL FOR PRACTICAL COURSES MSc Computer Science 2nd year Practical File of Visual Basic (CS-DE-27) DIRECTORATE OF DISTANC EDUCATION KURUKSHETRA UNIVERSITY, KURUKSHETRA. HARYANA- 136119 PRACTICAL EXAMINATION - Name- Mohit Roll No.- Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 3. EDUCATION DIRECTORATE OF DISTANCE (Established by the State Legislature Act XII of 1956) KURUKSHETRA UNIVERSITY, KURUKSHETRA Department of Computer Science This is to certify that this is the bonafide record work of practical work done by Mr. MOHIT Reg.No. 22248593 Roll No. Of MSc Computer Science 2nd year ,Of Subject CS-DE-27 (Visual Basic), at the Directorate of Distance Education, Kurukshetra University, Kurukshetra during the academic year. July 2022 - 2023 . Internal Examiner External Examiner Name- Mohit Roll No.- Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 4. Visual Basic (CS-DE- 27) Software Lab – II CONTENTS Sl. No. Title of the Exercise Page No. 1. Print the Sentence 04 2. String Concatenation 05 3. Vowel or Not 06 4. String Conversion 07 5. Simple Calculator 08 6. Online Examination 12 7. Loading of Control 14 8. Dynamic Menus 17 9. Analog Clock 19 10. Picture Viewer 23 11. Tic-Tac-Toe 27 12. Drag-Drop Recycle Bin 30 13. Traffic Light 32 14. Plotter 36 15. GP( Geometric Progression) 38 16. A Smart Audio Player 41 Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 5. Excercise Number - 1: Print the sentence Aim: To write a program to print the sentence "Write First program in Visual basic" Algorithm: 1. Start the application 2. To create a module 3. To declare the variable string as dimension 4. Assign any sentence to the variable as str 5. To display the sentence 6. End the Module 7. Deploy and run the program Source Code: Module Module1 Sub Main() Dim str As String str = "Write First program in Visual basic" Console.WriteLine(str) Console.ReadLine() End Sub End Module Output: Write First Program in Visual basic Result: Thus the program was executed and its output was verified. Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 6. Excercise Number - 2: String Concatenation Aim: To write a program to concatenate any two or more strings in Visual basic. Algorithm: 1. Start the application 2. To create a module and declare the variable string as dimension 3. Assign any word to each of the variables 4. To concatenate all the words and print them 5. End the module 6. Deploy and run the program Source Code: Module Module1 Sub Main() Dim str1, str2, str3 As String str1 = "Visual" str2 = "Basic" str3 = "Program" Console.WriteLine(str1 + " " + str2 + " " + str3) Console.ReadLine() End Sub End Module Output: Visual basic program Result: Thus the program was executed and its output was verified. Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 7. Excercise Number - 3: Vowel or not Aim: To write a program to check whether a character is vowel or not. Algorithm: 1. Start the application and create and design a form with needed buttons 2. Click the button to write the program in editor page 3. To declare the variable as string 4. To create textbox and assign the textbox values as variable 5. If the textbox values as vowel then the message box displays “The Given String is vowel” 6. Otherwise the messagebox displays “The Given String is not vowel” 7. Deploy and run the program Source Code: Public Class Vowels Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim c As String c = TextBox1.Text If c = "a" Or c = "A" Or c = "e" Or c = "E" Or c = "i" Or c = "I" Or c = "o" Or c = "O" Or c = "u" Or c = "U" Then MsgBox("The Given String is vowel") Else MsgBox("The Given String is not vowel") End If End Sub End Class Output: Result: Thus the program was executed and its output was verified. Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 8. Excercise Number - 4: String Conversion Aim: To write a program to accept character for console and check the case of the character. Algorithm: 1. Start the application 2. Open a new file and design the form with needed such controls as labelbox, textbox,button. 3. Click the button to write the program in editor page 4. Check the string is lower or upper case 5. Deploy and run the program Source Code: Public Class Conversion Private Sub Low_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Low.Click TextBox2.Text = TextBox1.Text.ToLower End Sub Private Sub Upp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Upp.Click TextBox2.Text = TextBox1.Text.ToUpper End Sub End Class Output: Result: Thus the program was executed and its output was verified. Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 9. Excercise Number - 5: Simple Calculator Aim: To write a program to develop a simple calculator for an arithmetic operations Algorithm: 1. Start the application 2. Open a new file and design the form with needed such controls as labelbox, textbox,button. 3. Click the button to write the program in editor page 4. Click the +,-,*,/ operator to prefer their respective operations 5. Use if else condition to do all the operations of arithmetic calculations 6. Deploy and run the program Source code: Public Class Form1 Dim frstnum As Decimal Dim scndnum As Decimal Dim operations As Integer Dim operator_selector As Boolean = False Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text <> "0" Then TextBox1.Text += "1" Else TextBox1.Text = "1" End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If TextBox1.Text <> "0" Then TextBox1.Text += "2" Else TextBox1.Text = "2" End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If TextBox1.Text <> "0" Then TextBox1.Text += "3" Else TextBox1.Text = "3" End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 10. If TextBox1.Text <> "0" Then TextBox1.Text += "4" Else TextBox1.Text = "4" End If End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If TextBox1.Text <> "0" Then TextBox1.Text += "5" Else TextBox1.Text = "5" End If End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click If TextBox1.Text <> "0" Then TextBox1.Text += "6" Else TextBox1.Text = "6" End If End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click If TextBox1.Text <> "0" Then TextBox1.Text += "7" Else TextBox1.Text = "7" End If End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click If TextBox1.Text <> "0" Then TextBox1.Text += "8" Else TextBox1.Text = "8" End If End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click If TextBox1.Text <> "0" Then TextBox1.Text += "9" Else TextBox1.Text = "9" End If End Sub Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 11. Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click If TextBox1.Text <> "0" Then TextBox1.Text += "0" End If End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click frstnum = TextBox1.Text TextBox1.Text = "0" operator_selector = True operations = 1 '=+ End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click frstnum = TextBox1.Text TextBox1.Text = "0" operator_selector = True operations = 2 '=- End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click frstnum = TextBox1.Text TextBox1.Text = "0" operator_selector = True operations = 3 '=* End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click frstnum = TextBox1.Text TextBox1.Text = "0" operator_selector = True operations = 4 '=/ End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click If Not (TextBox1.Text.Contains(".")) Then TextBox1.Text += "." End If End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click TextBox1.Text = "0" End Sub Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 12. If operator_selector = True Then scndnum = TextBox1.Text If operations = 1 Then TextBox1.Text = frstnum + scndnum ElseIf operations = 2 Then TextBox1.Text = frstnum - scndnum ElseIf operations = 3 Then TextBox1.Text = frstnum * scndnum ElseIfscndnum = 0 Then TextBox1.Text = "Error!" Else TextBox1.Text = frstnum / scndnum End If operator_selector = False End If End Sub End Class Output: Result: Thus the program was executed and its output was verified. Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 13. Excercise Number - 6: Online Examination Aim: To write a program to create Online Examination Using Timer. Algorithm: 1. Start the application 2. Open a new file and design the form with needed such controls as labelbox, textbox,button. 3. Click the button to write the editor page 4. Set a Timer as an interval = 1000 seconds 5. To declare all the variables 6. Radio button is used for the answer selection in the online exam 7. Use the message box to display the result 8. Deploy and run the program Source Code: Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Interval = 1000 Label3.Text = 20 Timer1.Enabled = True End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label3.Visible = False Dim total As Integer total = 0 If RadioButton1.Checked = True Then total += 1 End If If RadioButton3.Checked = True Then total += 1 End If MsgBox("Your Mark is " & total) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If Label3.Text = 0 Then Timer1.Enabled = False MsgBox("Timeout") Else Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 14. Label3.Text = Label3.Text Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 15. End ClassPublic Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Interval = 1000 Label3.Text = 20 Timer1.Enabl ed = True End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label3.Visib le = False Dim total As Integer total = 0 If RadioButton1.Checked = True Then total += 1 End If If RadioButton3.Checked = True Then total += 1 End If MsgBox("Your Mark is " & total) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If Label3.Text = 0 Then Timer1.Enabl ed = False MsgBox("Tim eout") Else Label3.Text = Label3.Text - 1 End Output: Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 16. Practical – 7 LOADING CONTROLS AT RUNTIME: Write a program which demonstrates the loading of controls at runtime. Dim i As Integer Dim lblindex As Integer Dim btnindex As Integer Private Sub cmd_btn_Click(Index As Integer) ' first give the index =0 to command button at design time Load cmd_btn(btnindex) With cmd_btn(btnindex) .Caption = "Button " & btnindex .Left = 3800 .Top = 1200 + btnindex * 500 .Height = 300 .Visible = True End With btnindex = btnindex + 1 End Sub Private Sub cmd_lbl_Click() Set lblnew = Controls.Add("VB.Label", "Labels" & lblindex) With lblnew .Caption = "Label " & lblindex .Left = 800 .Top = 1200 + lblindex * 500 .Visible = True End With lblindex = lblindex + 1 End Sub Private Sub cmd_Remove_Button_Click() If btnindex > 1 Then btnindex = btnindex - 1 Unload cmd_btn(btnindex) Else MsgBox ("There is no Button to remove") End If End Sub Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 17. Private Sub cmd_remove_Label_Click() If lblindex > 1 Then lblindex = lblindex - 1 Me.Controls.Remove ("Labels" & lblindex) Else MsgBox ("There is no label to remove") End If End Sub Private Sub cmd_Remove_Tbox_Click() If i > 1 Then i = i - 1 Me.Controls.Remove ("TextBox" & i) Else MsgBox ("There is no TextBox to remove") End If End Sub Private Sub cmd_tbox_Click() Set txtnew = Controls.Add("VB.TextBox", "TextBox" & i) txtnew.Text = "TextBox " & i ' move left, top, width , height txtnew.Move 2200, 1200 + i * 500, 1400, 20 txtnew.Visible = True i = i + 1 End Sub Private Sub Form_Load() i = 1 btnindex = 1 lblindex = 1 End Sub Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 18. Practical – 8 Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 19. DYNAMIC MENUS: Write a program which demonstrates the dynamic menus. For example the recently visited files are added in menus which changes dynamically. Dim Index As Integer Private Sub cmd_execute_Click() If Index < 5 Then Index = Index + 1 Load FileRecent(Index) FileRecent(Index).Enabled = True End If Dim i As Integer i = Index Do While i > 1 FileRecent(i).Caption = FileRecent(i - 1).Caption i = i - 1 Loop FileRecent(1).Caption = tbox_command.Text tbox_command.Text = "" tbox_command.SetFocus End Sub Private Sub FileExit_Click() End End Sub Private Sub FileRecent_Click(Index As Integer) tbox_command.Text = FileRecent(Index).Caption End Sub Private Sub FileReset_Click() For i = 1 To Index Unload FileRecent(i) Next End Sub Private Sub Form_Load() FileRecent(0).Enabled = False Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 20. End Sub Practical – 9 Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 21. ANALOG CLOCK: Write a program to create an analog clock, which shows all the three hands (Hour, Minute and second). You can add an option to change the background of the clock. Dim min, hour As Integer Const PI = 3.14159265 'Pi constant Dim theta As Single Dim dtheta As Single Dim second As Long Dim cx As Single Dim cy As Single Dim radius As Single Const stheta As Single = 4.7142857 Private Sub btn_image_Click() CommonDialog1.Filter = "Graphics|*.bmp;*.gif;*.jpg|Text File|*.txt|All Files|*.*" CommonDialog1.ShowOpen If Not Picture1.AutoRedraw Then Picture1.AutoRedraw = True Picture1.Picture = LoadPicture(CommonDialog1.Filename) Picture1.PaintPicture Picture1.Picture, 0, 0, 5000, 5000 gettime End Sub Public Sub gettime() theta = stheta dtheta = 2 * PI / 60 cx = 2500 cy = 2500 radius = 2300 second = Format(Time, "s") + Format(Time, "n") * 60 + (Format(Time, "h") Mod 12) * 3600 min = second / 60 hour = Format(Time, "h") Mod 12 LineSec.X1 = 2500 LineSec.Y1 = 2500 theta = stheta + (second Mod 60) * dtheta Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 22. LineSec.x2 = cx + (radius - 100) * Cos(theta) LineSec.y2 = cy + (radius - 100) * Sin(theta) line_minute.X1 = 2500 line_minute.Y1 = 2500 line_Hour.X1 = 2500 line_Hour.Y1 = 2500 line_Hour.x2 = cx + (radius - 200) * Cos(stheta + (2 * PI / 3600) * min * 5) line_Hour.y2 = cy + (radius - 200) * Sin(stheta + (2 * PI / 3600) * min * 5) End Sub Private Sub cmd_ForeColor_Click() CommonDialog1.ShowColor For i = 0 To Label14.Count - 1 Label14(i).ForeColor = CommonDialog1.color Next i Shape1.BorderColor = CommonDialog1.color DrawCircle 2500, 2500, 2400, 60, CommonDialog1.color End Sub Private Sub Form_Load() 'LoadDots DrawCircle 2500, 2500, 2400, 60 gettime End Sub Private Sub Timer2_Timer() second = second + 1 theta = theta + dtheta line_minute.x2 = cx + (radius - 100) * Cos(stheta + (2 * PI / 3600) * second) line_minute.y2 = cy + (radius - 100) * Sin(stheta + (2 * PI / 3600) * second) If second Mod 60 = 0 Then theta = 4.7142857 min = min + 1 line_Hour.x2 = cx + (radius - 200) * Cos(stheta + (2 * PI / 3600) * min * 5) line_Hour.y2 = cy + (radius - 200) * Sin(stheta + (2 * PI / 3600) * min * 5) Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 23. If second = 43200 Then second = 0 End If If min = 720 Then min = 0 End If X = cx + radius * Cos(theta) Y = cy + radius * Sin(theta) LineSec.x2 = X LineSec.y2 = Y End Sub Private Sub DrawCircle(ByVal cx As Single, ByVal cy As Single, ByVal radius As Single, ByVal num_segments As Integer, Optional fcolor As ColorConstants) Const PI = 3.14159265 Dim X As Single Dim Y As Single Dim theta As Single Dim dtheta As Single Dim second As Integer For i = 1 To Dot.Count - 1 Unload Dot(i) Next dtheta = 2 * PI / num_segments theta = stheta For seg = 1 To num_segments theta = theta + dtheta X = cx + radius * Cos(theta) Y = cy + radius * Sin(theta) Load Dot(seg) Dot(seg).X1 = X Dot(seg).Y1 = Y Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 24. Dot(seg).x2 = X + 2 Dot(seg).y2 = Y + 2 Dot(seg).BorderWidth = 3 If seg Mod 5 = 0 Then Dot(seg).BorderWidth = 5 Else Dot(seg).BorderColor = fcolor End If Dot(seg).Visible = True Next seg End Sub Practical – 10 Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 25. PICTURE VIEWER: Create a program that enables the users to open and choose files from the folders in their PC. The picture viewer provides the functionality to move to the NEXT and PREVIOUS photos, ZOOM IN & ZOOM OUT Dim Index As Integer Dim path As String Dim X, Y As Integer Private Sub bnt_prev_Click() If Index > 0 Then Index = Index - 1 End If path = File1.path If Right(path, Len(path) - 2) <> "" Then path = path & "" End If PictureViewer.Picture1.Picture = LoadPicture(path & File1.List(Index)) PictureViewer.Picture1.PaintPicture PictureViewer.Picture1.Picture, 0, 0, 800, 600 End Sub Private Sub btn_next_Click() If Index < File1.ListCount - 1 Then Index = Index + 1 path = File1.path If Right(path, Len(path) - 2) <> "" Then path = path & "" End If Picture1.Picture = LoadPicture(path & File1.List(Index)) Picture1.PaintPicture Picture1.Picture, 0, 0, 800, 600 Picture2.Picture = LoadPicture(path & File1.List(Index)) End If End Sub Private Sub btn_open_Click() openFolderDialog.Show 1 End Sub Private Sub btn_zoomin_Click() Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 26. If Picture1.Picture = 0 Then Exit Sub End If X = X + 80 Y = Y + 60 Picture1.Height = Y Picture1.Width = X Picture1.PaintPicture Picture1.Picture, 0, 0, X, Y If X > Pic_holder.ScaleWidth Then HScroll1.Max = X - Pic_holder.ScaleWidth VScroll1.Max = Y - Pic_holder.ScaleHeight Else HScroll1.Max = 0 VScroll1.Max = 0 End If End Sub Private Sub btn_zoomout_Click() If Picture1.Picture = 0 Then Exit Sub End If If X > 160 Then X = X - 80 Y = Y - 60 End If Picture1.Height = Y Picture1.Width = X Picture1.PaintPicture Picture1.Picture, 0, 0, X, Y If Picture1.ScaleWidth - Pic_holder.ScaleWidth > 0 Then HScroll1.Max = Picture1.ScaleWidth - Pic_holder.ScaleWidth VScroll1.Max = Picture1.ScaleHeight - Pic_holder.ScaleHeight Else HScroll1.Max = 0 VScroll1.Max = 0 End If Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 27. End Sub Private Sub Form_Load() X = 800 Y = 600 'Set up picturebox With Picture1 .ScaleMode = vbPixels .AutoRedraw = True .DrawMode = vbInvert .DrawStyle = SelDrawType .BackColor = vbWhite .MousePointer = vbCrosshair .Left = 0 .Top = 0 .ScaleHeight = Pic_holder.ScaleHeight .ScaleWidth = Pic_holder.ScaleWidth End With Picture2.ScaleHeight = Picture1.ScaleHeight Picture2.ScaleWidth = Picture1.ScaleWidth HScroll1.Max = Picture1.ScaleWidth - Pic_holder.ScaleWidth HScroll1.min = 0 VScroll1.Max = Picture1.ScaleHeight - Pic_holder.ScaleHeight HScroll1.min = 0 End Sub Private Sub HScroll1_Change() Picture1.Left = -HScroll1.Value End Sub Private Sub VScroll1_Change() Picture1.Top = -VScroll1.Value End Sub Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 28. Practical – 11 TIC- TAC- TOE: Develop a program Tic Tac Toe in VB so that you can play the game virtually. First of all, you need to draw the interface with four straight lines, then insert nine Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 29. image controls and make them an array, Image1 (0) to Image1 (8). Secondly, insert two pictures, one is a circle and the other one is a cross to represent player 1 and player2. Dim sym As String Dim winr(9) As String Private Sub Form_Load() sym = "X" Dim i As Integer For i = 0 To 8 winr(i) = i Next i End Sub Private Sub Label1_Change() If Label1.Caption = "Player 1" Then sym = "X" Else sym = "0" End If End Sub Private Sub lbl_gstatus_Click(Index As Integer) If lbl_gstatus(Index).Caption = "" Then lbl_gstatus(Index).Caption = sym winr(Index) = sym If Label1.Caption = "Player 1" Then Label1.Caption = "Player 2" Else Label1.Caption = "Player 1" End If check End If End Sub Function check() Dim i As Integer Dim won As Boolean Dim psymbol As String If winr(0) = winr(1) And winr(1) = winr(2) Then won = True psymbol = winr(0) ElseIf winr(2) = winr(4) And winr(4) = winr(6) Then Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 30. won = True psymbol = winr(2) ElseIf winr(0) = winr(3) And winr(3) = winr(6) Then won = True psymbol = winr(0) ElseIf winr(1) = winr(4) And winr(4) = winr(7) Then won = True psymbol = winr(1) ElseIf winr(2) = winr(5) And winr(5) = winr(8) Then won = True psymbol = winr(2) ElseIf winr(0) = winr(1) And winr(1) = winr(2) Then won = True psymbol = winr(0) ElseIf winr(3) = winr(4) And winr(4) = winr(5) Then won = True psymbol = winr(3) ElseIf winr(6) = winr(7) And winr(7) = winr(8) Then won = True psymbol = winr(6) End If If won = True Then Dim pno As Integer If psymbol = "X" Then pno = 1 Else pno = 2 End If MsgBox (" Player " & pno & " won") won = False For i = 0 To 8 winr(i) = i lbl_gstatus(i).Caption = "" Label1.Caption = "Player 1" Next End If End Function Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 31. Practical – 12 A DRAG & DROP RECYCLE_BIN: Make a drag and drop program that resembles a recycle bin. Drag and drop is a common windows application where you can drag and drop an object Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 32. such as a file into a folder or into a recycle bin. This capability can be easily programmed in visual basic Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single) Source.Visible = False End Sub Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then PopupMenu RestoreMenu, vbPopupMenuRightAlign End If End Sub Private Sub Restore_Click() Image1.Visible = True Image2.Visible = True Image3.Visible = True Image4.Visible = True End Sub Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 33. Practical – 13 TRAFFIC LIGHT: Create a Traffic light program in which, one can insert one timer and sets its interval according to its desire. Suppose set it to 3000, which is equivalent to 3 seconds. Next you insert three shapes and set their shape properties to circle and fill the colors. Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 34. Dim status(4) As Boolean Const interval As Integer = 1000 Dim wait As Integer Dim waittime(3) As Integer Dim stage, t1, t2, t3, t4 As Integer Private Sub Command1_Click() Me.FillColor = vbRed Me.FillStyle = vbSolid Call light(250, 50, 1) Call light(100, 200, 1) Call light(400, 200, 1) Call light(250, 300, 1) waittime(0) = 10 waittime(1) = 4 waittime(2) = 8 Timer2.Enabled = True Timer1.Enabled = True t1 = waittime(0) + waittime(1) t2 = (waittime(1) + waittime(2)) * 2 + 1 t3 = (waittime(1) + waittime(2)) * 3 + 1 t4 = (waittime(1) + waittime(2)) * 4 + 1 Label1.Left = 320 Label1.Top = 50 Label2.Left = 320 Label2.Top = 300 Label3.Left = 170 Label3.Top = 200 Label4.Left = 470 Label4.Top = 200 wait = 10 stage = 0 End Sub Function light(X As Integer, Y As Integer, Optional c As Integer) Call rectangle(X, Y, X + 50, Y + 100) Call fillcircle(X + 25, Y + 20, vbWhite) Call fillcircle(X + 25, Y + 50, vbWhite) Call fillcircle(X + 25, Y + 80, vbWhite) Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 35. Select Case c Case 1: Call fillcircle(X + 25, Y + 20, vbRed) Case 2: Call fillcircle(X + 25, Y + 50, vbYellow) Case 3: Call fillcircle(X + 25, Y + 80, vbGreen) End Select End Function Function rectangle(X As Integer, Y As Integer, x2 As Integer, y2 As Integer) Me.Line (X, Y)-(X, y2), vbRed Me.Line (x2, Y)-(x2, y2), vbRed Me.Line (X, Y)-(x2, Y), vbRed Me.Line (X, y2)-(x2, y2), vbRed End Function Function fillcircle(X As Integer, Y As Integer, color As ColorConstants) Me.FillColor = color Me.Circle (X, Y), 10, vbBlack End Function Private Sub Timer1_Timer() t1 = t1 - 1 t2 = t2 - 1 t3 = t3 - 1 t4 = t4 - 1 Label1.Caption = t1 Label2.Caption = t2 Label3.Caption = t3 Label4.Caption = t4 End Sub Private Sub Timer2_Timer() stage = stage + 1 Select Case stage Case 1: Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 36. Call light(250, 50, 2) Timer2.interval = interval * waittime(1) Case 2: Call light(250, 50, 3) Call light(400, 200, 1) t1 = waittime(2) Timer2.interval = interval * waittime(2) Case 3: Call light(250, 50, 2) Call light(250, 300, 2) t1 = (waittime(1) + waittime(2)) * 3 + waittime(1) Timer2.interval = interval * waittime(1) Case 4: Call light(250, 50, 1) Call light(250, 300, 3) t2 = waittime(2) Timer2.interval = interval * waittime(2) Case 5: Call light(100, 200, 2) Call light(250, 300, 2) t2 = (waittime(1) + waittime(2)) * 3 + waittime(1) Timer2.interval = interval * waittime(1) Case 6: Call light(100, 200, 3) Call light(250, 300, 1) t3 = waittime(2) Timer2.interval = interval * waittime(2) Case 7: Call light(100, 200, 2) Call light(400, 200, 2) t3 = (waittime(1) + waittime(2)) * 3 + waittime(1) Timer2.interval = interval * waittime(1) Case 8: Call light(100, 200, 1) Call light(400, 200, 3) t4 = waittime(2) Timer2.interval = interval * waittime(2) Case 9: Call light(250, 50, 2) Call light(400, 200, 2) t4 = (waittime(1) + waittime(2)) * 3 + waittime(1) Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 37. Timer2.interval = interval * waittime(1) stage = 1 End Select End Sub Practical – 14 CUBIC FUNCTION GRAPH PLOTTER: Make a program that enables users to input the coefficients of a cubic equation and draw its graph. The cubic equation takes the form ax3 +bx2 +cx+d. Private Sub btn_cls_Click() pic_graph.Cls End Sub Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 38. Private Sub cmd_draw_Click() Dim a, b, c, d As Integer Dim w, v As Double a = Val(tbox_a.Text) b = Val(tbox_b.Text) c = Val(tbox_c.Text) d = Val(tbox_d.Text) 'Using a scale of 0.5 cm to represent i unit to draw the graph ' Need to make some transformation as the coordinates in VB start from top left For w = 0 To 10 Step 0.001 v = a * (5 - w) ^ 3 + b * (5 - w) ^ 2 + c * (5 - w) + d pic_graph.PSet (w, 5 - v) Next w End Sub Private Sub Form_Load() Line_x.X1 = 0 Line_x.x2 = pic_graph.ScaleWidth Line_x.Y1 = pic_graph.ScaleHeight / 2 Line_x.y2 = pic_graph.ScaleHeight / 2 Line_y.X1 = pic_graph.ScaleWidth / 2 Line_y.x2 = pic_graph.ScaleWidth / 2 Line_y.Y1 = 0 Line_y.y2 = pic_graph.ScaleHeight End Sub Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 39. Practical – 15 GEOMETRIC PROGRESSION: Make a Visual Basic program that can compute a geometric progression and display the results in a list box. Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 40. Private Sub btn_sum_Click() Dim a, n As Integer Dim r As Single If check() = False Then MsgBox ("Required fields are empty") Exit Sub End If If opt_inputbox.Value Then a = InputBox("First Term", "Geometric Progression", 1) r = InputBox("Common Ratio", "Geometric Progression", 1) n = InputBox("How many terms", "Geometric Progression", 1) Else a = tbox_fn.Text r = tbox_r.Text n = tbox_terms.Text End If Dim s As Single If r > 1 Then s = (a * ((r ^ n) - 1)) / (r - 1) Else s = (a * (1 - (r ^ n))) / (1 - r) End If MsgBox ("The sum is " & s) End Sub Private Sub btn_term_Click() Dim a, n As Integer Dim r As Single If check() = False Then MsgBox ("Required fields are empty") Exit Sub End If If opt_inputbox.Value Then a = InputBox("First Term", "Geometric Progression", 1) r = InputBox("Common Ratio", "Geometric Progression", 1) n = InputBox("Which Term you want to display", "Geometric Progression", 1) Else a = tbox_fn.Text r = tbox_r.Text n = tbox_terms.Text Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 41. End If MsgBox ("The " & n & "th term is " & a * (r ^ (n - 1))) End Sub Private Sub cmd_Clear_Click() List1.Clear End Sub Private Sub cmd_series_Click() If check() = False Then MsgBox ("Required fields are empty") Exit Sub End If cmd_Clear_Click Dim f, n, terms As Integer Dim r As Single f = tbox_fn.Text r = tbox_r.Text terms = tbox_terms.Text List1.AddItem "Term" & vbTab & "Value" List1.AddItem "-----------------------" n = 1 Do List1.AddItem n & vbTab & f * (r ^ (n - 1)) n = n + 1 Loop While n <= terms End Sub Function check() As Boolean If tbox_fn.Text = "" Then check = False ElseIf tbox_r.Text = "" Then check = False ElseIf tbox_terms.Text = "" Then check = False Else check = True End If End Function Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 42. Practical – 16 A SMART AUDIO PLAYER: Write a program to create a player that enables you to play midi and wave files in your hard drives or floppy A or CDROM. It should allow you to change drives and search for the particular sound file that you wish to play. In this program, you have to add a Combo box, a List Box, a Text Box, a Drive List Box, a command button you label as Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 43. "PLAY", another command button you label as "STOP", and one more command button you label as "EXIT". You have to add in MMControl and make it invisible. Dim i As Integer Private Sub btn_exit_Click() End End Sub Private Sub btn_Play_Click() If File1.ListCount = 0 Then Exit Sub Timer1.Enabled = True Slider1.Value = 0 MMControl1.Command = "Close" MMControl1.Filename = File1.path & "" & File1.List(i) MMControl1.Command = "Open" MMControl1.Command = "Play" File1.Selected(i) = True i = i + 1 If i >= File1.ListCount Then i = 0 End If End Sub Private Sub btn_Stop_Click() If btn_Stop.Caption = "Resume" Then MMControl1.Command = "Play" btn_Stop.Caption = "Pause" Else MMControl1.Command = "Pause" btn_Stop.Caption = "Resume" End If End Sub Private Sub cbox_pattern_Click() If cbox_pattern.ListIndex = 0 Then File1.Pattern = "*.wav;*.midi" Else File1.Pattern = "*.mp3;*.wav;*.mp4;*.mpeg;*.avi;*.dat" Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 44. End If End Sub Private Sub Dir1_Change() File1.path = Dir1.path End Sub Private Sub Drive1_Change() Dir1.path = Drive1.Drive End Sub Private Sub File1_Click() i = File1.ListIndex btn_Play_Click End Sub Private Sub Form_Load() File1.Pattern = "*.midi;*.wav" MMControl1.PlayEnabled = True MMControl1.AutoEnable = True End Sub Private Sub Timer1_Timer() Slider1.Value = Round(MMControl1.Position / MMControl1.Length * 100) End Sub Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983
  • 45. Name- Mohit Roll No. - Downloaded by BALWAN SAINI (sainibalwan86@gmail.com) lOMoARcPSD|28417983