You are on page 1of 53

Proramming in vb.

net Bca 3 rd year

Assignment-1

Program -Write a program to find maximum between three numbers

Source code:-
Imports System
Module Module1 Sub Main()
Console.WriteLine(" sherya thakur BCA 3rd year")
Dim a, b, c As Integer
Console.Write("Enter the values of a , b and c :")
a = CInt(Console.ReadLine())
b = CInt(Console.ReadLine())
b = CInt(Console.ReadLine())
If (a > b) And (a > c) Then
Console.WriteLine("Maximum=" + a.ToString())
ElseIf (b > a) And (b > c) Then
Console.WriteLine("Maximum=" + b.ToString())
Else
Console.WriteLine("Maximum=" + c.ToString())
End If
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 1


Proramming in vb.net Bca 3 rd year

Assignment 2

Program -Write a program to check whether a number is negative, positive


or zero.

sourceCode:
Imports System
Module Number
Sub Main()
Console.WriteLine(" sherya thakur BCA 3rd year")
Dim num As Integer = 0
Console.Write("Enter number: ")
num = Integer.Parse(Console.ReadLine())
If num> 0 Then
Console.WriteLine("Entered Number is Positive.")
ElseIfnum< 0 Then
Console.WriteLine("Entered Number is Negative.")
Else
Console.WriteLine("Entered Number is Zero.")
End If
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 2


Proramming in vb.net Bca 3 rd year

Assignment 3

Program-Write a program to check whether a year is leap year or not.


sourceCode:
Imports System
Module Module1
Sub Main()
Console.WriteLine(" sherya thakur BCA 3rd year")
Dim year As Integer = 0
Console.Write("Enter the year : ")
year = Integer.Parse(Console.ReadLine())
If (((year Mod 4 = 0) AndAlso Not (year Mod 100 = 0)) OrElse ((year Mod 4 = 0) AndAlso (year
Mod 100 = 0) AndAlso (year Mod 400 = 0))) Then
Console.WriteLine("Entered year is leap year")
Else
Console.WriteLine("Entered year is not a leap year")
End If
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 3


Proramming in vb.net Bca 3 rd year

Assignment 4

Program Write a program to check whether a character is alphabet or not.-


sourceCode:
Imports System
Module Module1
Sub Main()
Console.WriteLine(" sherya thakur BCA 3rd year")
Dim ch As Char
Console.Write("Enter the Character : ")
ch = Char.Parse(Console.ReadLine())
If ((ch>= "a") And (ch<= "z") Or (ch>= "A") And (ch<= "Z")) Then
Console.WriteLine("Entered character is Alphabet")
Else
Console.WriteLine("Entered character is Numeric")
End If
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 4


Proramming in vb.net Bca 3 rd year

Assignment 5
Program-Write a program to find all roots of a quadratic equation.
sourceCode:
Imports System
Module Module1
Sub Main()
Console.WriteLine(" sherya thakur BCA 3rd year")
Dim a, b, c, s, r1, r2 As Double
Console.WriteLine("Enter 3 number : ")
a = Console.ReadLine()
b = Console.ReadLine()
c = Console.ReadLine()
s = (b * b - (4 * a * c)) ^ 2
r1 = (b + s) / (2 * a)
r2 = (-b + s) / (2 * a)
Console.WriteLine("root 1: {0} ", r1)
Console.WriteLine("root 2: {0} ", r2)
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 5


Proramming in vb.net Bca 3 rd year

Assignment 6
Program-Design an application to input marks of five subjects Physics,
Chemistry, Biology, Mathematics and Computer. Calculate percentage and
grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 90% : Grade F
sourceCode:
Module Student
Sub Main()
Console.WriteLine(" sherya thakur BCA 3rd year")
Dim p, c, b, m, cp, total As Integer
Dim per As Decimal
Console.WriteLine("Enter marks of Physics, Chemistry, Biology, Mathematics and Computer :")
p = Console.ReadLine()
c = Console.ReadLine()
b = Console.ReadLine()
m = Console.ReadLine()
cp = Console.ReadLine()
total = 0
Console.WriteLine("Entered marks of" + vbCrLf + "Physics = {0}" + vbCrLf + "Chemistry = {1}"
+ vbCrLf + "Biology = {2}" + vbCrLf + "Mathematics = {3}" + vbCrLf + "Computer = {4}", p,
c, b, m, cp)
total = (p + c + b + m + cp)
Console.WriteLine(vbCrLf + "Total Marks = {0}", total)
per = ((p + c + b + m + cp) / 500) * 100
Console.WriteLine(vbCrLf + "Percentage = {0}", per)
If (per >= 90) Then
Console.WriteLine("Grade A")
ElseIf (per >= 80) Then
Console.WriteLine("Grade B")
ElseIf (per >= 70) Then
Console.WriteLine("Grade C")
ElseIf (per >= 60) Then
Console.WriteLine("Grade D")
ElseIf (per >= 40) Then
Console.WriteLine("Grade E")
Else
Console.WriteLine("Grade F")
End If
Console.ReadLine()

Name- Shreya thakur Page 6


Proramming in vb.net Bca 3 rd year

End Sub
End Module

Output:

Name- Shreya thakur Page 7


Proramming in vb.net Bca 3 rd year

Assignment 7
Program-Design an application to input basic salary of an employee and calculate
its Gross salary according to following:
Basic Salary <= 10000 : HRA = 20%, DA =80%
Basic Salary <= 20000 : HRA = 25%, DA =90%
Basic Salary > 20000 : HRA = 30%, DA =95%
sourceCode:
Module Module3
Sub Main()
Console.WriteLine(" sherya thakur BCA 3rd year")
Dim hra, da, bs, gs As Decimal
Console.WriteLine(vbCrLf + "Enter Basic Salary : ")
bs = Console.ReadLine()
If (bs<= 10000) Then
hra = bs * (20 / 100)
da = bs * (80 / 100)
ElseIf (bs<= 20000) Then
hra = bs * (25 / 100)
da = bs * (90 / 100)
Else
hra = bs * (30 / 100)
da = bs * (95 / 100)
End If
gs = bs + da + hra
Console.WriteLine(vbCrLf + "Your Gross salary is {0}", gs)
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 8


Proramming in vb.net Bca 3 rd year

Assignment 8
Program-Design an application to input electricity unit changes and calculate
total electricity bill according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/units
For unit above 250 Rs. 1.50/units
An additional surcharges of 20% is added to the bill
Source code :-
Module Module1
Sub Main()
Console.WriteLine("Shreya Thakur Bca3rd year")
Dim usg, bill, sc As Decimal
Console.WriteLine("vbCrLf+enter consumed unit :")
usg = Console.ReadLine()
Console.WriteLine("vbCrL+ entered consumed unit is :{0}", usg)
If (usg <= 50) Then
bill = usg * 0.5
ElseIf (usg <= 150) Then
bill = (50 * 0.5) + ((usg - 50) * 0.75)
ElseIf (usg <= 250) Then
bill = (50 * 0.5) + (100 * 0.75) + ((usg - 150) * 1.2)
Else
bill = (50 * 0.5) + (100 * 0.75) + (10 * 1.2) + ((usg - 250) * 1.5)
End If
sc = bill * (25 / 100)
bill = sc + bill
Console.WriteLine("your electicity bill is :{0}", bill)
Console.ReadLine()
End Sub
End Module
Output:-

Name- Shreya thakur Page 9


Proramming in vb.net Bca 3 rd year

Assignment 9

Program-Write a program to convert decimal to binary number system using


bitwise operator.

sourceCode:
Module

Sub Main()

Console.WriteLine(" sherya thakur BCA 3rd year")

Dim n, i, b As Integer
Console.WriteLine("Enter a number : ")
n = Console.ReadLine()
Console.WriteLine(" Binary of {0} is : ", n)
For i = 15 To 0 Step -1
b = n >>i
If (b = 1) Then
Console.WriteLine("1")
Else
Console.WriteLine("0")
End If
Next
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 10


Proramming in vb.net Bca 3 rd year

Assignment 10
Program-Write a program to swap two numbers using bitwise operator.
sourceCode:
Module Program_10
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Dim num1, num2 As Integer
console.writeline("Enter two numbers:")
num1 = console.readline()
num2 = console.readline()
console.writeline("Numbers before swapping were : {0} {1}", num1, num2)
num1 = num1 Xor num2
num2 = num1 Xor num2
num1 = num1 Xor num2
Console.WriteLine("Numbers after swapping are : {0} {1}", num1, num2)
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 11


Proramming in vb.net Bca 3 rd year

Assignment 11

Program-Write a program to create Simple Calculator using select case.


sourceCode:
Module Module1
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Dim a, b, c As Integer
Dim o As Char
Console.WriteLine("Enter 1st number: ")
a = Console.ReadLine()
Console.WriteLine("Enter your operator: ")
o = Console.ReadLine()
Console.WriteLine("Enter 2nd number: ")
b = Console.ReadLine()
Select Case o
Case "+"
c=a+b
Case "-"
c=a-b
Case "*"
c=a*b
Case "\"
c=a\b
Case Else
Console.WriteLine("You have entered a wrong operator")
End Select
Console.WriteLine("Arithmetic Calculation of {0} {1} {2} is {3}", a, o, b, c)
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 12


Proramming in vb.net Bca 3 rd year

Assignment 12

Program-Write a program to find sum of all natural numbers between 1 to n.


sourceCode:
Module Module1
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Dim a = 0
Dim i = 0
Dim s = 0
console.writeline("Enter any Natural number:")
a = console.readline()
If (a > 0) Then
For i = 1 To a Step 1
s=s+i
Next
console.writeline("Sum of natural numbers from 1 to {0} is {1}", a, s)
Else
console.writeline("Entered Number is not an integer")
End If
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 13


Proramming in vb.net Bca 3 rd year

Assignment 13

Program-Write a program to find first and last digit of any number.

sourceCode:
Sub Main()

Console.WriteLine("Shreya Thakur Bca 3rd year")

Dim n, first, last As Long

Console.WriteLine("***Program to find first & last digit of any number***")

n = Console.ReadLine()
last = n Mod 10
first = n
While (first >= 10)
first = first / 10
End While
Console.WriteLine("first digit:-{0}", first)
Console.WriteLine("last digit:-{0}", last)
Console.WriteLine("enter any key for exit!!!")
Console.ReadLine()
End Sub
End Module
Output:

Name- Shreya thakur Page 14


Proramming in vb.net Bca 3 rd year

Assignment- 14
Program-Write a program to enter any number and print its reverse.
sourceCode:
Module Module1
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Console.WriteLine("Enter digit:")
n = Console.ReadLine()
u=n
While (n <> 0)
m = n Mod 10
r = r * 10 + m
n = n \ 10
End While
Console.WriteLine("Reverse of {0} is {1}", u, r)
Console.ReadLine()
End Sub
End Module
Output :

Name- Shreya thakur Page 15


Proramming in vb.net Bca 3 rd year

Assignment -15
Program-Write a program to enter any number and check whether the number is palindrome
or not.
sourceCode:
Module Module1
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Dim number As Integer = 0
Dim remainder As Integer = 0
Dim reverse As Integer = 0
Dim temp As Integer = 0
Console.WriteLine("Enter your number: ")
number = Console.ReadLine()
Console.WriteLine("Entered number is : {0} ", number)
temp = number
While (number > 0)
remainder = number Mod 10
reverse = reverse * 10 + remainder
number = number / 10
End While
If temp = reverse Then
Console.WriteLine("Entered Number is palindrome")
Else
Console.WriteLine("Entered Number is not palindrome")
End If
Console.ReadLine()
End Sub
End Module
Output :

Name- Shreya thakur Page 16


Proramming in vb.net Bca 3 rd year

Assignment -16
Program-Write a program to check whether a number is Armstrong number or not.
sourceCode:
Module Module6
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Dim number As Integer = 0
Dim temp As Integer = 0
Dim remainder As Integer = 0
Dim result As Integer = 0
Console.WriteLine("Enter the number: ")
number = Console.ReadLine()
Console.WriteLine("Entered number is : {0} ", number)
temp = number
While (temp > 0)
remainder = (temp Mod 10)
result = result + (remainder * remainder * remainder)
temp = temp \ 10
End While
If (number = result) Then
Console.WriteLine("armstrong")
Else
Console.WriteLine("not armstrong")
End If
Console.ReadLine()
End Sub
End Module
Output :

Name- Shreya thakur Page 17


Proramming in vb.net Bca 3 rd year

Assignment -17

Program-Write a program to print Fibonacci series up to n terms.


sourceCode:
Module Module7
Sub main()
Console.WriteLine("sherya thakur BCA 3rd year ")

Dim n, f1, f2, f3 As Integer


Console.Write("Enter n:")
n = Console.ReadLine()
f1 = 0
f2 = 1
f3 = 0
While n <> 0
Console.WriteLine("fibnocci series of n terms:{0} ", f3)
f1 = f2
f2 = f3
f3 = f1 + f2
n -= 1
End While
Console.ReadLine()
End Sub
End Module
Output :

Name- Shreya thakur Page 18


Proramming in vb.net Bca 3 rd year

Assignment -18

Program-Write a program to print Pascal triangle up to n rows.

sourceCode:
Module Module

Sub Main()

Console.WriteLine("sherya thakur BCA 3rd year ")

Dim arr As Integer(,) = New Integer(5, 5) {}


For i As Integer = 0 To 5
For k As Integer = 5 To i + 1 Step -1
'print spaces
Console.Write(" ")
Next
For j As Integer = 0 To i - 1
If j = 0
Elseif j Then
arr(i, j) = 1
Else
arr(i, j) = arr(i - 1, j) + arr(i - 1, j - 1)
End If
Console.Write(arr(i, j) & " ")
Next
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module
Output :

Name- Shreya thakur Page 19


Proramming in vb.net Bca 3 rd year

Assignment -19

Program-Write a program to print all negative elements in an array.

Source Code:

Module Module9
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Dim m(100), i, n As Integer
console.writeline("Enter the numbers :-")
n = console.readline()
For i = 1 To n
console.writeline("Enter integers {0}", i)
m(i) = console.readline()
Next
console.writeline("Negative numbers in the Array are :- ")
For i = 1 To n
If (m(i) < 0) Then
console.writeline("{0}", m(i))
End If
Next
Console.Writew+Line(" Press any key to exit...")
Console.ReadKey()

End Sub
End Module
Output :

Name- Shreya thakur Page 20


Proramming in vb.net Bca 3 rd year

Assignment-20

Program-Design a digital clock using timercontrol.


Source code:-
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock
Public Class Frmdigital
Private Sub Frmdigital_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
lbTime.Text = TimeOfDay
lbDtae.Text = Date.Today.ToString("dd MMM yyyy")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
lbTime.Text = TimeOfDay
End Sub
End Class

Output:

Name- Shreya thakur Page 21


Proramming in vb.net Bca 3 rd year

Assignment- 21

Program:-Design the application that accepts the item name from the user and add it to a
listbox and combobox:

Source code:-
Public Class Form1

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


ListBox1.Items.Add(TextBox1.Text)
ComboBox1.Items.Add(TextBox1.Text)
End Sub
End Class
Output :-

Name- Shreya thakur Page 22


Proramming in vb.net Bca 3 rd year

Assignment 22
Program -Create an application that offers various food items to select from
check boxes and a mode of payment using radio button. It then display the total
amount payable

sourceCode:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
Console.WriteLine("("sheryathakur BCA 3rd year ")
Dim sum As Integer
If (CheckBox1.Checked) Then
sum = sum + 60
End If
If (CheckBox2.Checked) Then
sum = sum + 80
End If
If (CheckBox3.Checked) Then
sum = sum + 100
End If
If (CheckBox4.Checked) Then
sum = sum + 120
End If
If (CheckBox5.Checked) Then
sum = sum + 130
End If
If (RadioButton1.Checked) Then
Label1.Text = sum
Label2.Text = "is paid by Cash"
Else
Label1.Text = sum
Label2.Text = "is paid by Card"
End If
Console.ReadLine()
End Sub
End Class
Output :

Name- Shreya thakur Page 23


Proramming in vb.net Bca 3 rd year

Assignment.23
Program : Create an application to implement the working of Context menu on
textbox.
Source code:

Public Class Form1


Private Sub CutToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CutToolStripMenuItem.Click
RichTextBox1.Cut()
End Sub

Private Sub COPYToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles COPYToolStripMenuItem1.Click
RichTextBox1.Copy()
End Sub

Private Sub PASTEToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles PASTEToolStripMenuItem1.Click
RichTextBox1.Paste()
End Sub

Private Sub EXITToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles EXITToolStripMenuItem1.Click
Me.Close()
End Sub
End Class
Output :-

Name- Shreya thakur Page 24


Proramming in vb.net Bca 3 rd year

Assignment-24
Program -WAP to illustrate all functionalities of list box and combo box.
sourceCode:
public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
' creating multi-column and multiselect list box
ListBox1.MultiColumn = True
ListBox1.SelectionMode = SelectionMode.MultiExtended
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
ListBox1.Items.Add("Safety")
ListBox1.Items.Add("Security")
ListBox1.Items.Add("Governance")
ListBox1.Items.Add("Good Music")
ListBox1.Items.Add("Good Movies")
ListBox1.Items.Add("Good Books")
ListBox1.Items.Add("Education")
ListBox1.Items.Add("Roads")
ListBox1.Items.Add("Health")
ListBox1.Items.Add("Food for all")
ListBox1.Items.Add("Shelter for all")
ListBox1.Items.Add("Industrialisation")
ListBox1.Items.Add("Peace")
ListBox1.Items.Add("Liberty")
ListBox1.Items.Add("Freedom of Speech")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
ListBox1.Sorted = True
End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
ListBox1.Items.Clear()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
ListBox1.Items.Remove(ListBox1.SelectedItem.ToString)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button5.Click
Label1.Text = ListBox1.Items.Count
End Sub

Name- Shreya thakur Page 25


Proramming in vb.net Bca 3 rd year

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ListBox1.SelectedIndexChanged
Label2.Text = ListBox1.SelectedItem.ToString()
End Sub
End Class
Output:-

Name- Shreya thakur Page 26


Proramming in vb.net Bca 3 rd year

Assignment – 25
Program:- WAP using a checkboxes for the following font effect:-
• Bold
• Italic
• Underline
• Increasing font size
• Decreasing font size
• Font color

Source code:-
Public Class Form1

Private Sub FontDialog1_Apply(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles FontDialog1.Apply
Me.Text = "javaTpoint.com" 'set the title name for the Windows form.
Button1.Text = "Change Font" 'Set the name of button1
Button2.Text = "Exit" 'name of button2
Label1.Text = "Uses of Font"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
FontDialog1.ShowColor = True
If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
richTextBox1.Font = FontDialog1.Font 'Change the font of the selected string
richTextBox1.ForeColor = FontDialog1.Color 'Change the color of selected string
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Me.Dispose() 'Terminate the program
End Sub
End Class
Output:

Name- Shreya thakur Page 27


Proramming in vb.net Bca 3 rd year

Name- Shreya thakur Page 28


Proramming in vb.net Bca 3 rd year

Assignment -26

Program -WAP for temperature conversion using radio button.

sourceCode:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
If RadioButton1.Checked = True Then
Label1.Text = MaskedTextBox1.Text & " Fahrenheit = " & (MaskedTextBox1.Text = 32) / 1.8
&" Celsius"
ElseIf RadioButton2.Checked = True Then
Label1.Text = MaskedTextBox1.Text & " Celsius = " & (MaskedTextBox1.Text * 1.8) +
32 &" Fahrenheit"
End If
End Sub
End Class
Output :

Name- Shreya thakur Page 29


Proramming in vb.net Bca 3 rd year

Assignment – 27
Program:- WAP to lauch a rocket using picturebox and time control
Source code :-
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
PictureBox1.Top = PictureBox1.Top - 1
PictureBox1.Left = PictureBox1.Left + 1

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
Timer1.Start()

End Sub
End Class
Output:-

Name- Shreya thakur Page 30


Proramming in vb.net Bca 3 rd year

Assignment -28
Program -WAP to change the back color of any control using scroll box.

sourceCode:
Public Class Form1
Dim r As Integer = 0
Dim g As Integer = 0
Dim b As Integer = 0
Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll

r = VScrollBar1.Value()
Me.BackColor = Color.FromArgb(r, g, b)

End Sub

Private Sub VScrollBar2_Scroll(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.ScrollEventArgs) Handles VScrollBar2.Scroll
g = VScrollBar2.Value()
Me.BackColor = Color.FromArgb(r, g, b)

End Sub

Private Sub VScrollBar3_Scroll(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.ScrollEventArgs) Handles VScrollBar3.Scroll
b = VScrollBar3.Value()
Me.BackColor = Color.FromArgb(r, g, b)

End Sub
End Class

Output :

Name- Shreya thakur Page 31


Proramming in vb.net Bca 3 rd year

Assignment -29

Program-WAP to search an element for one dimensional array.


sourceCode:
Module Module1
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Dim arr As Integer() = New Integer(5) {}
Dim item As Integer = 0
Dim flag As Integer = -1
Dim i As Integer = 0
Console.WriteLine("Enter array elements: ")
For i = 0 To 4 Step 1
Console.Write("Element[{0}]: ", i)
arr(i) = Integer.Parse(Console.ReadLine())
Next
Console.WriteLine("Enter item for searching: ")
item = Integer.Parse(Console.ReadLine())
For i = 0 To 4 Step 1
If item = arr(i) Then
flag = i
GoTo out
End If
Nextout:
If flag <> -1 Then
Console.WriteLine("Item found at index {0} in array", flag)
Else
Console.WriteLine("Item is not found")
End If
Console.ReadLine()
End Sub
End Module
Output :

Name- Shreya thakur Page 32


Proramming in vb.net Bca 3 rd year

Assignment – 30
Program-WAP to find greatest among three given number using user define
procedures.
sourceCode:
Module Module1
Sub Main()
Console.WriteLine("sherya thakur BCA 3rd year ")
Dim result As Integer = 0
Dim num1 As Integer = 0
Dim num2 As Integer = 0
Dim num3 As Integer = 0
Console.Write("Enter number1: ")
num1 = Integer.Parse(Console.ReadLine())
Console.Write("Enter number2: ")
num2 = Integer.Parse(Console.ReadLine())
Console.Write("Enter number3: ")
num3 = Integer.Parse(Console.ReadLine())
result = If(
(num1 > num2 AndAlso num1 > num3), num1, If((num2 > num1 AndAlso num2 >
num3), num2, num3))
Console.WriteLine("GREATEST Number is: {0}", result)
Console.ReadLine()
End Sub
End Module
Output :

Name- Shreya thakur Page 33


Proramming in vb.net Bca 3 rd year

Assignment- 31
Program -wap a program to calculate factorial of a number using user define
procedures.
sourceCode:
Module Module1
Sub Main()
Dim n, i, f As Integer
Console.Write("Enter a Number: ")
Console.WriteLine("shreya thakur Bca 3rd year")

n = CInt(Console.ReadLine())
f=1
If n < 0 Then
Console.WriteLine("Factorial of negative number is possible")
ElseIf n = 0 Or n = 1 Then
Console.WriteLine("Factorial of " + n.ToString() + " is1")
Else
For i = 1 To n
f *= i
Next
Console.WriteLine("Factorial of " + n.ToString() + " is
+ f.ToString())
End If
Console.ReadLine()
End Sub

End Module
Output:-

Name- Shreya thakur Page 34


Proramming in vb.net Bca 3 rd year

Assignment- 32
Program:-Design the following application using radio button and checkbox :
Source code:-
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
TextBox1.Text = "You Selected a "
If RadioButton1.Checked = True Then
TextBox1.Text = TextBox1.Text & RadioButton1.Text
ElseIf RadioButton2.Checked = True Then
TextBox1.Text = TextBox1.Text & RadioButton2.Text
ElseIf RadioButton3.Checked = True Then
TextBox1.Text = TextBox1.Text & RadioButton3.Text
End If
If RadioButton5.Checked = True Or RadioButton5.Checked = True Then
TextBox1.Text = TextBox1.Text &" with "
End If
If RadioButton5.Checked = True Then
TextBox1.Text = TextBox1.Text & RadioButton5.Text
ElseIf RadioButton5.Checked = True Then
TextBox1.Text = TextBox1.Text & RadioButton5.Text
End If
If CheckBox1.Checked Then
TextBox1.Text = TextBox1.Text & CheckBox1.Text
End If
If CheckBox1.Checked Or CheckBox2.Checked Or CheckBox3.Checked Or
CheckBox4.Checked Then
TextBox1.Text = TextBox1.Text & "And Accessories :"
End If
If CheckBox1.Checked = True Then
TextBox1.Text = " " & TextBox1.Text & CheckBox2.Text & " "
End If
If CheckBox2.Checked = True Then
TextBox1.Text = " " & TextBox1.Text & CheckBox2.Text & " "
End If
If CheckBox3.Checked = True Then
TextBox1.Text = " " & TextBox1.Text & CheckBox3.Text & " "
End If
If CheckBox4.Checked = True Then
TextBox1.Text = " " & TextBox1.Text & CheckBox4.Text & " "
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click

Name- Shreya thakur Page 35


Proramming in vb.net Bca 3 rd year

End Sub

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles GroupBox1.Enter

End Sub
End Class

Output:-

Name- Shreya thakur Page 36


Proramming in vb.net Bca 3 rd year

Assignment -33
Program:-Design an application to create the payroll from shown below.
Number of hours must be entered as the appropriate rate.
Gross salary=rate*hours.
Net salary=gross salary-deduction.
Source code:-
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
Dim A As Integer
Dim B As Integer
Dim C As Integer
' Dim d As Integer
A = TextBox2.Text
C = TextBox3.Text
B = 10

If (RadioButton1.Checked) Then
TextBox4.Text = A * B
ElseIf (RadioButton2.Checked) Then
TextBox4.Text = A * B
Else
(RadioButton3.Checked) Then
TextBox4.Text = A * B
End If

TextBox5.Text = TextBox4.Text - C

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Me.Close()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
End
End Sub
End Class

Output:-

Name- Shreya thakur Page 37


Proramming in vb.net Bca 3 rd year

Name- Shreya thakur Page 38


Proramming in vb.net Bca 3 rd year

Assignment – 34
Program:-develop an application which is similar to note pad using menu

Making Notepad in Windows Forms:


Step 1: Open Visual Studio and Create a new project( Windows Form Application).
Give it a Suitable name(Here we have named it as “NotePad1”).
Step 2: Click on the Create button. You will come across a Form as given below:

Step 3: Change the name of the form from its properties. This will be displayed on
the top of the Notepad as its heading.
From Toolbox, select menu strip and place it on the top in the form area. In MenuStrip, you
can provide the names of the various options that you want in your notepad. We are
adding File, Edit, and Format options in the menu. You can add more as per your choice.
Step 4: Now in the options provided in the MenuBar, we need to have a dialog box
that will open up as the user clicks on the File, Edit, or Font option. Therefore, we
will provide further options for them.

For FILE
Similarly, for Edit and Font, we will add the options as shown below: will add
options as follows:

Name- Shreya thakur Page 39


Proramming in vb.net Bca 3 rd year

Assignment 35
Program:- Develop an application which is similar to login form.
Source code:-
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
Dim obj As New login
Else
Dim obj As New login(TextBox1.Text, TextBox2.Text)
If (TextBox1.Text = "Pallavi" And TextBox2.Text = "2000") Then
obj.loginfun(TextBox1.Text)
Else
obj.loginfun()
End If
End If
End Sub
End Class
Public Class login
Dim username, password As String
Public Sub New()
MsgBox("Enter Username And Password", MsgBoxStyle.Information, "")
End Sub
Public Sub New(ByVal user As String, ByVal pass As String)
username = user
password = pass
End Sub
Overloads Sub loginfun()
MsgBox("You are not a valid user", MsgBoxStyle.Critical, "")
End Sub
Overloads Sub loginfun(ByVal user As String)
MsgBox("Welcome " & username, MsgBoxStyle.OkOnly)
End Sub
End Class
Output :-

Name- Shreya thakur Page 40


Proramming in vb.net Bca 3 rd year

Name- Shreya thakur Page 41


Proramming in vb.net Bca 3 rd year

Assignmen- 36
Program –Define structure student.struture student has data members for
storing name,roll no, name of three subject and marks.write member funcation
to store and print data.
sourceCode:
Public Class Form1
Private Structure Student
Public Name As String
Public RollNo As Integer
Public Sub1 As String
Public Sub2 As String
Public Sub3 As String
Public Marks1 As Integer
Public Marks2 As Integer
Public Marks3 As Integer
End Structure
Dim Struct As Student
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Struct.Name = TextBox1.Text
Struct.RollNo = TextBox2.Text
Struct.Sub1 = TextBox3.Text
Struct.Sub1 = TextBox4.Text
Struct.Sub3 = TextBox5.Text
Struct.Marks1 = TextBox6.Text
Struct.Marks2 = TextBox7.Text
Struct.Marks3 = TextBox8.Text
Me.DataGridView1.Rows.Add(Struct.Name, Struct.RollNo, Struct.Sub1, Struct.Sub2, Struct.Sub3,
Struct.Marks1, Struct.Marks2, Struct.Marks3)
End Sub
Endclass
Output:-

Name- Shreya thakur Page 42


Proramming in vb.net Bca 3 rd year

Name- Shreya thakur Page 43


Proramming in vb.net Bca 3 rd year

Assignment -37
Program-Write a class having name calculate that uses static overloaded
funcation to calculated area of circle,area of rectangle,,areaof triangle.
sourceCode:
Module Module1
Class geometry
Overloads Function area(ByVal r As Double)
Return 3.14 * r * r

End Function
Overloads Function area(ByVal l As Double, ByVal b As Double)
Return l * b
End Function
Overloads Function area(ByVal base As Integer, ByVal h As Integer)

Return (base * h) / 2

End Function
End Class

Sub Main()
Dim geo As geometry = New geometry
Console.WriteLine("Shreya thakur Bca 3rd year")
Console.WriteLine("Area of circle=" & geo.area(2.5))
Console.WriteLine("Area of rectangle=" & geo.area(2.5, 5.0))
Console.WriteLine("Area of triangle =" & geo.area(2, 5))
Console.ReadLine()

End Sub

End Module

Output:-

Name- Shreya thakur Page 44


Proramming in vb.net Bca 3 rd year

Assignment-38
Program : WAP to demonstrate concept of Polymorphism (function
Overloading and constructor Overloading).
Source code:
Module Module1
Class Sample
Private num As Integer
Public Sub New()
Console.WriteLine("Default or no argument constructor called to initialize data
members")
num = 10
End Sub
Public Sub New(ByVal n As Integer)
Console.WriteLine("Parameterized constructor called to initialize data members")
num = n
End Sub
Public Sub Print()
Console.WriteLine("Value of num: {0}", num)
Console.ReadLine()

End Sub
End Class
Sub Main()
Dim obj1 As New Sample()
Dim obj2 As New Sample(20)
obj1.Print()
obj2.Print()
End Sub
End Module

Name- Shreya thakur Page 45


Proramming in vb.net Bca 3 rd year

Funcation overloading :-
Module Module1
Class geometry
Overloads Function area(ByVal r As Double) As Integer
Return 3.14 * r * r
End Function
Overloads Function area(ByVal l As Double, ByVal b As Double) As Double
Return l * b
End Function
End Class
Sub Main()
Console.WriteLine("Name:Sherya Thakur")
Console.WriteLine("Class:- BCA 3rd Year")
Dim geo As geometry = New geometry()
Console.WriteLine("Area of circle =" & geo.area(2.5))
Console.WriteLine("Area of rect=" & geo.area(2.5, 5.0))
Console.ReadKey()
End Sub
End Module

Name- Shreya thakur Page 46


Proramming in vb.net Bca 3 rd year

Assignment 39
Program: WAP to display records of a tables using data adapter and code for
buttons to move at first record ,next record, previous record , last record in
the table.

Design Window:-

Table view:-

Source code :-
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
'TODO: This line of code loads data into the 'Database3DataSet.Table1' table. You can
move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Database3DataSet.Table1)

End Sub

Name- Shreya thakur Page 47


Proramming in vb.net Bca 3 rd year

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
Table1BindingSource.MovePrevious()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Table1BindingSource.AddNew()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
Table1BindingSource.MoveNext()

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button6.Click
On Error GoTo SaveError
Table1BindingSource.EndEdit()
Table1TableAdapter.Update(Database3DataSet.Table1)
MsgBox("Data has been Saved")
SaveError:
Exit Sub
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button5.Click
Table1BindingSource.RemoveCurrent()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
Me.Close()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button7.Click
Table1BindingSource.MoveLast()

End Sub

Name- Shreya thakur Page 48


Proramming in vb.net Bca 3 rd year

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button8.Click
Table1BindingSource.MoveFirst()

End Sub
End Class

Output:-

Name- Shreya thakur Page 49


Proramming in vb.net Bca 3 rd year

Assignment 40

Program: Create a table for employee and write a program using dataset to add
, delete , edit & navigate records.

Form Design:

Source Code:
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\user\AppData\Local\Temporary Projects\Practicle\Practicle.accdb")
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim cmd As OleDbCommand
Dim count, maxRow As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
If con.State = ConnectionState.Closed Then
con.Open()
MsgBox("connected")
End If
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button5.Click
Dim sql As String
da = New OleDbDataAdapter
sql = "insert into emp values(" & TextBox1.Text.Trim & ",'" & TextBox2.Text.Trim & "',"
& TextBox3.Text.Trim & ",'" & TextBox4.Text.Trim & "')"
Name- Shreya thakur Page 50
Proramming in vb.net Bca 3 rd year

cmd = New OleDbCommand(sql, con)


da.InsertCommand = cmd
da.InsertCommand.ExecuteNonQuery()
MsgBox("Record saved")
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button6.Click
Dim sql As String
da = New OleDbDataAdapter
sql = "update emp set ID=" & TextBox1.Text.Trim & ", name='" & TextBox2.Text.Trim &
"', sal=" & TextBox3.Text.Trim & ",desg='" & TextBox4.Text.Trim & "' where ID=" &
TextBox1.Text.Trim & ""
cmd = New OleDbCommand(sql, con)
da.UpdateCommand = cmd
da.UpdateCommand.ExecuteNonQuery()
MsgBox("Record Updated")
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button7.Click
Dim sql As String
da = New OleDbDataAdapter
sql = "delete from emp where ID=" & TextBox1.Text.Trim & ""
cmd = New OleDbCommand(sql, con)
da.DeleteCommand = cmd
da.DeleteCommand.ExecuteNonQuery()
MsgBox("Record Deleted")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
setDataToTextbox("select * from emp")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
da = New OleDbDataAdapter("Select * from emp", con)
ds = New DataSet()
da.Fill(ds, "emp")
maxRow = ds.Tables(0).Rows.Count
count = count - 1
If count <= -1 Then
MsgBox("first record")
Exit Sub
End If
TextBox1.Text = ds.Tables(0).Rows(count).Item(0)

Name- Shreya thakur Page 51


Proramming in vb.net Bca 3 rd year

TextBox2.Text = ds.Tables(0).Rows(count).Item(1)
TextBox3.Text = ds.Tables(0).Rows(count).Item(2)
TextBox4.Text = ds.Tables(0).Rows(count).Item(3)
da.Dispose()
ds.Dispose()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
da = New OleDbDataAdapter("Select * from emp", con)
ds = New DataSet()
da.Fill(ds, "emp")
maxRow = ds.Tables(0).Rows.Count
count = count + 1
If count > maxRow - 1 Then
MsgBox("Last record")
Exit Sub
End If
TextBox1.Text = ds.Tables(0).Rows(count).Item(0)
TextBox2.Text = ds.Tables(0).Rows(count).Item(1)
TextBox3.Text = ds.Tables(0).Rows(count).Item(2)
TextBox4.Text = ds.Tables(0).Rows(count).Item(3)

da.Dispose()
ds.Dispose()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
da = New OleDbDataAdapter("Select * from emp", con)
ds = New DataSet()
da.Fill(ds, "emp")
count = ds.Tables(0).Rows.Count - 1
TextBox1.Text = ds.Tables(0).Rows(count).Item(0)
TextBox2.Text = ds.Tables(0).Rows(count).Item(1)
TextBox3.Text = ds.Tables(0).Rows(count).Item(2)
TextBox4.Text = ds.Tables(0).Rows(count).Item(3)

da.Dispose()
ds.Dispose()
End Sub
Public Sub setDataToTextbox(ByVal sql As String)
da = New OleDbDataAdapter(sql, con)
ds = New DataSet()
da.Fill(ds, "emp")
count = 0
TextBox1.Text = ds.Tables(0).Rows(count).Item(0)

Name- Shreya thakur Page 52


Proramming in vb.net Bca 3 rd year

TextBox2.Text = ds.Tables(0).Rows(count).Item(1)
TextBox3.Text = ds.Tables(0).Rows(count).Item(2)
TextBox4.Text = ds.Tables(0).Rows(count).Item(3)

da.Dispose()
ds.Dispose()
End Sub
End Class

Input & Output:

Name- Shreya thakur Page 53

You might also like