Вы находитесь на странице: 1из 37

Visual .

NET Technologies

Practical File

Akshansh Kumar
BCA 4A
A1004817012
1. Write a program to perform following operation:
a. ADD
b. SUBTRACT
c. MULTIPLY
d. DIVISION
e. MOD

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


TextBox3.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


TextBox3.Text = Val(TextBox1.Text) * Val(TextBox2.Text)
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


TextBox3.Text = Val(TextBox1.Text) / Val(TextBox2.Text)
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click


TextBox3.Text = Val(TextBox1.Text) Mod Val(TextBox2.Text)
End Sub
End Class
2. Write a program, using recursive function to generate Fibonacci Series.
Public Class Form1
Function fib(ByVal n As Integer) As Integer
If (n = 0 Or n = 1) Then
Return n
Else
Return fib(n - 1) + fib(n - 2)
End If
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim n As Integer = TextBox2.Text
While (n >= 0)
Dim s As String = fib(n)
TextBox1.Text += s + " "
n -= 1
End While

End Sub
End Class
3. Write a program to add two matrices
Module Module1

Sub Main()
Dim m, n, c, d As Int16
Dim first(,) As Int16 = New Int16(5, 5) {}
Dim second(,) As Int16 = New Int16(5, 5) {}
Dim sum(,) As Int16 = New Int16(5, 5) {}
Console.WriteLine("Enter the number of rows and columns of matrix")
m = Convert.ToInt16(Console.ReadLine())
n = Convert.ToInt16(Console.ReadLine())
Console.WriteLine("\nEnter the elements of first matrix\n")
c=0
While c < m
d=0
While d < n
Console.WriteLine("Enter Element [" + c.ToString() + " , " + d.ToString() + "]")
first(c, d) = Convert.ToInt16(Console.ReadLine())
d=d+1
End While
c=c+1
End While
Console.WriteLine("Enter the elements of second matrix")
c=0
While c < m
d=0
While d < n
Console.WriteLine("Enter Element [" + c.ToString() + " , " + d.ToString() + "]")
second(c, d) = Convert.ToInt16(Console.ReadLine())
d=d+1
End While
c=c+1
End While
c=0
While c < m
d=0
While d < n
sum(c, d) = first(c, d) + second(c, d)
d=d+1
End While
c=c+1
End While
Console.WriteLine("Sum of entered matrices:-")
c=0
While c < m
d=0
While d < n
Console.Write(" " + sum(c, d).ToString())
d=d+1
End While
Console.WriteLine()
c=c+1
End While
Console.ReadKey()
End Sub
End Module

4. Create a list box, which contains names of all cinema halls of NCR. If you choose name of
cinema hall, label display information regarding all movies running in the cinema halls
Public Class Form1
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles
ListBox1.SelectedIndexChanged
Dim n As String = ListBox1.SelectedItem
If (n = "Miraj M4U") Then
TextBox1.Text = "URI
Bumblebee
Simmba
"
ElseIf (n = "World Square") Then
TextBox1.Text = "URI
The accidental Prime Minister"
ElseIf (n = "DLF") Then
TextBox1.Text = "URI
The accidental Prime Minister
Simmba"
ElseIf (n = "GIP") Then
TextBox1.Text = "URI
NTR
The acidental Prime Minister
Simmba"
ElseIf (n = "Wave") Then
TextBox1.Text = "URI
The accidental Prime Minister
KGF
NTR
Simmba"
End If
End Sub

End Class
5. Create and validate login form.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form2.Hide()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (TextBox1.Text = "7052776" And TextBox2.Text = "123###aks") Then
MessageBox.Show("Hello Akshansh")
Form2.Show()
Else
MessageBox.Show("Invalid credentials")
End If
End Sub

Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles


CheckBox1.CheckedChanged
If TextBox2.UseSystemPasswordChar = True Then
TextBox2.UseSystemPasswordChar = False
Else
TextBox2.UseSystemPasswordChar = True
End If
End Sub
End Class

Public Class Form2


Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Hide()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Application.Restart()
End Sub
End Class
6. Write a program to calculate pay that takes two parameters hours and wages and display
the total pay of an employee.

Public Class Form1


Dim hour, basic, overtime As Integer

hour = Val(TextBox2.Text)
basic = Val(TextBox1.Text)
overtime = Val(TextBox3.Text)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


TextBox4.Text = basic + hour * overtime
End Sub

End Class
7. Write a program to print first n square less than 50 and print the sum of the all the square of
the n number

Public Class Form1


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim n As Integer = 1
Dim sum As Integer = 0
Dim x As String
While n * n < 50
x=n*n
sum += n * n
n += 1
TextBox1.Text += x + " "
End While
TextBox2.Text = sum
End Sub
End Class
8. Create a project for book sales. Make text boxes for quantity, title and price with labels.
Calculate total price, discount (15%) and discounted price.
Make command buttons for calculate, clear and exit.

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim price As Integer = Val(TextBox1.Text) * Val(TextBox3.Text)
TextBox4.Text = price
TextBox5.Text = price - (0.15 * price)
End Sub
End Class
9. Create a project for the local car rental agency that calculates rental charges. The agency
charge $15 per day + $0.50 per km. use text boxes for
customer name, address, city, state, zip code, beginning and ending audiometer reading and
no. of days the car was used. Use labels to display the miles
given and the total charges. Make command buttons for clear, exit and calculate.

Public Class Form1

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


Dim miles As String = Val(TextBox6.Text) - Val(TextBox5.Text)
Dim cost As String = Val(TextBox7.Text * 15) + (Val(TextBox6.Text) - Val(TextBox5.Text)) * 0.5
Label9.Text += cost
Label8.Text += miles
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


Application.Exit()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Application.Restart()
End Sub
End Class
10. Create a project that will input an employee salary. Calculate a gross salary, deduction and
net salary. Each employee will receive a basic pay of $900 +
sales commission of 6% of sales. After calculating the net paid calculate the budget amount of
each category based on the % given.
i. Bank pays $900
ii. Commission 6% of sales
iii. Gross pay Basic pay + Commission
iv. Deduction 18% of gross pay
v. Net pay Gross pay – deduction
Budget:-
Housing 30% of net pay
Food and clothing 15% of net pay
Entertainment 50% of net pay
Miscellaneous 5% of net pay
Use text boxes to input the employee name, amount of sales. Use labels to display the result
and the calculation. Use calculates, clear and exit command buttons.

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox2.Text = Val(TextBox1.Text) * 0.06
TextBox3.Text = Val(TextBox2.Text) + 900
TextBox4.Text = Val(TextBox3.Text) * 0.18
TextBox5.Text = Val(TextBox3.Text) - Val(TextBox4.Text)
TextBox6.Text = Val(TextBox5.Text) * 0.3
TextBox7.Text = Val(TextBox5.Text) * 0.15
TextBox8.Text = Val(TextBox5.Text) * 0.5
TextBox9.Text = Val(TextBox5.Text) * 0.05
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


Application.Exit()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


Application.Restart()
End Sub
End Class
11. Maintain a list of types of ice creams. Use a drop down combo box to hold the ice-cream
type and use command button to add, remove, clear, display
and exit. Don’t allow a blank type to be added to the list. Display an error message if the user
select remove without first selecting an ice-cream type.
Before clearing the list, display a message to confirm the operation.

Public Class Form1


Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles
ComboBox1.SelectedIndexChanged

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


If (ComboBox1.Text = "") Then
MessageBox.Show("Error! No Item Selected")
Else
ListBox1.Items.Add(ComboBox1.Text)
ComboBox1.Items.Add(ComboBox1.Text)
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


If (ComboBox1.SelectedItem = "") Then
MessageBox.Show("Error! No Item Selected")
Else
ListBox1.Items.Remove(ComboBox1.Text)
ComboBox1.Items.Remove(ComboBox1.Text)
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


If MsgBox("Are you sure?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Application.Restart()
End If

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click


Application.Exit()
End Sub
End Class
12. Write a program to find the area of a box(Length* breadth *height ) using class
Public Class Form1
Public Class box
Public length As Integer
Public breadth As Integer
Public height As Integer
Public volume As Integer
Public area As Integer
End Class
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim b1 As box = New box()
b1.length = Val(TextBox1.Text)
b1.breadth = Val(TextBox2.Text)
b1.height = Val(TextBox3.Text)
b1.area = 2 * (b1.length * b1.breadth + b1.breadth * b1.height + b1.height * b1.length)
b1.volume = b1.length * b1.breadth * b1.height
TextBox4.Text = b1.area
TextBox5.Text = b1.volume
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
End Class
13. Write a program to find how many times n object of the class is created.
Class count
Shared c As Integer = 0
Public Sub New()
c += 1
End Sub
Function display()
Dim d As String = c
MessageBox.Show(d + " Object(s) Created")
End Function
End Class
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a As New count()
a.display()
Dim b As New count()
b.display()
Dim c As New count()
c.display()
Application.Exit()
End Sub
End Class

14. Write a program to copy the content of one array to another .Also count the numbers of
elements present in the same.
Module Module1

Sub Main()
Dim arr1(10) As Integer
For i = 0 To 10
arr1(i) = i + 1
Next
Dim arr2(10) As Integer
For i = 0 To 10
arr2(i) = arr1(i)
Next
For i = 0 To 10
Console.WriteLine(arr2(i))
Next
Console.ReadKey()
End Sub

End Module

15. Write a program to swap the values of two variables using sub procedure.

Module Module1

Sub swap(ByRef n1 As Integer, ByRef n2 As Integer)


Dim temp As Integer = n1
n1 = n2
n2 = temp
End Sub

Sub Main()
Dim a As Integer = 10
Dim b As Integer = 20
Console.WriteLine("Before swapping")
Console.WriteLine("A: {0}", a)
Console.WriteLine("B: {0}", b)
swap(a, b)
Console.WriteLine("After swapping")
Console.WriteLine("A: {0}", a)
Console.WriteLine("B: {0}", b)
Console.ReadKey()
End Sub

16. Write a program to sort the array using Bubble sort.


Module Module1
Sub sort(ByRef a() As Integer, ByVal size As Integer)
For i = 0 To size
For j = 0 To i
If (a(i) < a(j)) Then
Dim temp As Integer = a(i)
a(i) = a(j)
a(j) = temp
End If
Next
Next
End Sub
Sub Main()
Dim a(10) As Integer
For i = 10 To 0 Step -1
a(i) = i + 1
Next
sort(a, 10)
For i = 0 To 10
Console.WriteLine(a(i))
Next
Console.ReadKey()
End Sub
End Module

17. Write a program to search an element in an array, using Binary Search.


Module Module1
Sub search(ByRef a() As Integer, ByVal size As Integer, ByVal s As Integer)
For i = 0 To size
If (a(i) = s) Then
Console.WriteLine("Element found as position: {0}", s)
End If
Next
End Sub
Sub Main()
Dim a(10) As Integer
For i = 10 To 0 Step -1
a(i) = i + 1
Next
search(a, 10, 5)
Console.ReadKey()
End Sub
End Module

18. Create a project to design a calculator using control array

Public Class Form1


Dim a As Double
Dim b As Double
Dim op As Char
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "0" Then
TextBox1.Text = "7"
Else
TextBox1.Text += "7"
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "8"
Else
TextBox1.Text += "8"
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "9"
Else
TextBox1.Text += "9"
End If
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "4"
Else
TextBox1.Text += "4"
End If
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "5"
Else
TextBox1.Text += "5"
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If TextBox1.Text = "0" Then
TextBox1.Text = "6"
Else
TextBox1.Text += "6"
End If
End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "1"
Else
TextBox1.Text += "1"
End If
End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "2"
Else
TextBox1.Text += "2"
End If
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "3"
Else
TextBox1.Text += "3"
End If
End Sub

Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "0"
Else
TextBox1.Text += "0"
End If
End Sub

Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click


If TextBox1.Text = "0" Then
TextBox1.Text = "0."
Else
TextBox1.Text += "."
End If
End Sub

Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click


a = Val(TextBox1.Text)
op = "+"
TextBox1.Text = ""
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
a = Val(TextBox1.Text)
op = "-"
TextBox1.Text = ""
End Sub

Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click


a = Val(TextBox1.Text)
op = "*"
TextBox1.Text = ""
End Sub

Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click


a = Val(TextBox1.Text)
op = "/"
TextBox1.Text = ""
End Sub

Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click


a = Val(TextBox1.Text)
op = "^"
TextBox1.Text = ""
End Sub

Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click


TextBox1.Clear()
End Sub

Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click


b = Val(TextBox1.Text)
If (op = "+") Then
TextBox1.Text = a + b
ElseIf op = "^" Then
TextBox1.Text = a ^ b
ElseIf op = "-" Then
TextBox1.Text = a - b
ElseIf op = "*" Then
TextBox1.Text = a * b
ElseIf op = "/" And b = 0 Then
TextBox1.Text = "Syntax Error"
ElseIf op = "/" Then
TextBox1.Text = a / b
End If
End Sub

End Class
19. Create a text editor application .It should perform operation like cut, copy, paste and
change in font, color of the selected text. Also implement new open and save-file menu
option. Write a program to implement the concept of function overloading.

Public Class Form1


Dim copy As String

Private Sub ToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles


ToolStripMenuItem2.Click
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 8, TextBox1.Font.Style)
End Sub

Private Sub ToolStripMenuItem3_Click(sender As Object, e As EventArgs) Handles


ToolStripMenuItem3.Click
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 10, TextBox1.Font.Style)
End Sub
Private Sub ToolStripMenuItem4_Click(sender As Object, e As EventArgs) Handles
ToolStripMenuItem4.Click
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 12, TextBox1.Font.Style)
End Sub

Private Sub ToolStripMenuItem5_Click(sender As Object, e As EventArgs) Handles


ToolStripMenuItem5.Click
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 14, TextBox1.Font.Style)
End Sub

Private Sub ToolStripMenuItem6_Click(sender As Object, e As EventArgs) Handles


ToolStripMenuItem6.Click
TextBox1.Font = New Font(TextBox1.Font.FontFamily, 16, TextBox1.Font.Style)
End Sub

Private Sub BlackToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


BlackToolStripMenuItem.Click
TextBox1.ForeColor = Color.Black
End Sub

Private Sub BlueToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


BlueToolStripMenuItem.Click
TextBox1.ForeColor = Color.Blue
End Sub
Private Sub RedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
RedToolStripMenuItem.Click
TextBox1.ForeColor = Color.Red
End Sub

Private Sub GreenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


GreenToolStripMenuItem.Click
TextBox1.ForeColor = Color.Green
End Sub

Private Sub YellowToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


YellowToolStripMenuItem.Click
TextBox1.ForeColor = Color.Yellow
End Sub

Private Sub DefaultToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


DefaultToolStripMenuItem.Click
TextBox1.Font = New Font("Microsoft Sans Serif", TextBox1.Font.Size,
TextBox1.Font.Style)
End Sub

Private Sub ComicSansToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


ComicSansToolStripMenuItem.Click
TextBox1.Font = New Font("Arial", TextBox1.Font.Size, TextBox1.Font.Style)
End Sub
Private Sub CalibriToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
CalibriToolStripMenuItem.Click
TextBox1.Font = New Font("Calibri", TextBox1.Font.Size, TextBox1.Font.Style)
End Sub

Private Sub TimesNewRomanToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles TimesNewRomanToolStripMenuItem.Click
TextBox1.Font = New Font("Times new roman", TextBox1.Font.Size, TextBox1.Font.Style)
End Sub

Private Sub ComicSansToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles


ComicSansToolStripMenuItem1.Click
TextBox1.Font = New Font("Comic Sans MS", TextBox1.Font.Size, TextBox1.Font.Style)
End Sub

Private Sub CopyToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles


CopyToolStripMenuItem1.Click
copy = TextBox1.SelectedText
End Sub

Private Sub PasteToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles


PasteToolStripMenuItem1.Click
TextBox1.SelectedText = copy
End Sub

Private Sub CutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


CutToolStripMenuItem.Click
copy = TextBox1.SelectedText
TextBox1.SelectedText = ""
End Sub

Private Sub NewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


NewToolStripMenuItem.Click
Application.Restart()
End Sub

Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


SaveToolStripMenuItem.Click
Dim file As String
file = InputBox("Enter file path and name")
Dim objWriter As New System.IO.StreamWriter(file)
objWriter.Write(TextBox1.Text)
objWriter.Close()
MessageBox.Show("File saved")
End Sub

Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


OpenToolStripMenuItem.Click
Dim file As String
file = InputBox("Enter file path and name")
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(file)
TextBox1.Text = fileReader
End Sub
End Class
20. Using exception handling write a program to divide two numbers.
Module Module1
Sub division(ByVal num1 As Integer, ByVal num2 As Integer)
Dim result As Integer
Try
result = num1 \ num2
Catch e As DivideByZeroException
Console.WriteLine("Exception caught: {0}", e)
Finally
Console.WriteLine("Result: {0}", result)
End Try
End Sub
Sub Main()
division(25, 0)
Console.ReadKey()
End Sub
End Module

Вам также может понравиться