Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

VB.

NET Assignment Page 1

INDEX
S. No. Name of Program Page Sign
no.
1 Write a program to find maximum between three numbers. 5

2 Write a program to check whether a number is negative, positive or Zero. 6

3 Write a program to check whether a year is leap year or not. 7


4 Write a program to check whether a character is alphabet or not. 8
5 Write a program to find all roots of a quadratic equation. 9-10
6 Design an application to input marks of five subjects physics, chemistry, 10-11
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 C
Percentage>=40% : grade E
Percentage<40% : grade F
7 Design an application to input basic salary of an employee and Gross 12-13
salary according to following:
Basic Salary <=10000 :HRA=20%,DA=80%
Basic Salary <=20000 :HRA=25%,DA=90%
Basic Salary >10000 :HRA=30%,DA=95%
8 Design an application which is similar to login from 14-15
9 WAP using checkbox for the following font effects. 16-19
Bold
Italic
Underline
Increase font size
Decrease font size
Font color
10 Design the form that calculate Sum, Multiplication, Division and 19-22
Subtraction of two number.
11 Design Simple calculator. 23-25
12 Design the form to input radius of a circle and find its circumference and 26
area.
13 Design the form to input length in centimeter and convert it into meter. 27
14 Design the form to input temperature in Celsius and convert it into 28
Fahrenheit.

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 2

15 Design the form to input Principal amount, Time, Rate and calculate 29-30
Simple
Interest and compound interest show result information in msgbox.

16 Design the form and write a program to sort array element in ascending 31-32
Order
17 Design the form and write a program to insert an element in an array. 33
18 Design the form and write a program to delete an element from an 34-35

array at specified position.


19 Design the form and write a program to print all unique elements in the 36—37
array.
20 Design a form to check whether a number is PRIME or NOT using input 38-39
box and msgbox.
21 Write a program to print Fibonacci series up to n terms. 40-41
22 Design the following form when user clicks on Radio Button then select 41-42
Checkbox.

23 Design the Digital watch using Timer Control. 43-44

24 Design the following form using horizontal scrollbar. In this, when user 45
click on particular scrollbar then back color of shape will be changed
to Red, Green & Blue color

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 3

25 Design the following form using vertical scrollbar. In this, when user 46-47
click on particular scrollbar then back color of shape will be changed
to Red, Green &Blue color

26 Design the form with different controls.


48-51

27 WAP for Exception handling of throwing an exception when dividing by 52


zero condition occur during arithmetic operation.

28 WAP in vb.net such that throw a user define exception when 53-54
Temperature is zero.

29 Design from that shows the functionality of listbox 55-57

30 Write a vb.net program to show data in Data grid view. 58


31 Create following table Student(id,name,course,DOB,address) Write 59-60
vb.net application to
1. Add records
2. View all the records

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 4

32 Develop a project which displays the student information in the relevant 61-63
fields from the database which already exists.

33 Define structure student. Structure student has data members for storing 63-64
name, rollno ,name of three subjects and marks. Write member function
to store and print data.
34 Write a class having name Calculate that uses static overloaded function 65-68
to calculate area of circle, area of rectangle and area of triangle.
35 WAP to check whether a given number is neon or not using user define 68
function.
36 WAP to check whether a given number is Niven or not using procedure. 69-70

37 WAP to check whether a given number is Duck number or not . 71

38 WAP to check whether a given number is Spy number or not . 72

39 Write a program to find first and last digit of any number. 73

40 Write a program to enter any number and print its reverse. 74

41 WAP to check whether a given number is Armstrong number or not. 75

42 WAP to enter any number and check whether the no. is palindrome or 76-77
not
43 WAP to calculate factorial of a number using user define procedure. 77

44 Create a class circle with data member radius; provide member function to 78-79
calculate area. Define a class sphere from class circle, provide member
function to calculate area class cylinder from class sphere with additional
data member for height and member function to calculate volume.

CONSOLE APPLICATION

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 5

Q. 1. Write a program to find maximum between three numbers.

Coding:-
Module maximum_number

Sub Main()
Dim a, b, c As Integer
Console.Write("Enter the a,b & c number = ")
a = CInt(Console.ReadLine()) b =
CInt(Console.ReadLine()) c =
CInt(Console.ReadLine())
If a > b Then
If a > c Then
Console.WriteLine("maximum number = " + a.ToString())
Else
Console.WriteLine("maximum number = " + c.ToString())
End If
Else
If b > c Then
Console.WriteLine("maximum number = " + b.ToString())
Else
Console.WriteLine("maximum number = " + c.ToString())
End If
End If
Console.ReadLine()
End Sub End
Module

Output:-

Q. 2. Write a program to check whether a number is negative, positive or Zero.

Program Code:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 6

Imports System

Module Program
Sub Main(args As String())
Dim n As Integer
Console.WriteLine("Enter value of n:-")
n = Console.ReadLine() If n >= 0 Then
If n = 0 Then
Console.WriteLine("n is zero : " & n)
Console.ReadLine()
Else
Console.WriteLine("n is Positive : " & n)
Console.ReadLine()
End If
Else
Console.WriteLine("n is Negative : " & n)
Console.ReadLine()
End If
End Sub
End Module

Output:--

Q. 3. Write a program to check whether a year is leap year or not.

Coding:-
Imports System

Module Leap_Year

Sub Main()
Dim year As Integer = 0

Console.Write("Enter year: ")

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 7

year = Integer.Parse(Console.ReadLine())

If ((year Mod 4 = 0) AndAlso (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 leap year")
End If
End Sub

End Module

Output:-

Q.4. Write a program to check whether a character is alphabet or not.

Coding:-

Imports System

Module Program
Sub Main(args As String())
Dim a As Char
Console.WriteLine("Enter Your Character : ")
a = Console.ReadLine() Select Case a
Case "a" To "z"
Console.WriteLine("Yes! it is Alphabet : " & a)
Console.ReadLine()

Case "A" To "Z"

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 8

Console.WriteLine("Yes! It is Alphabet : " & a)


Console.ReadLine()

Case Else
Console.WriteLine("No! It is Not an Alphabet : " & a)
Console.ReadLine()

End Select
End Sub
End Module

Output:-

Q. 5. Write a program to find all roots of a quadratic equation.

Coding:-
Imports System

Module Program
Sub main()
Dim a, b, c, r1, r2 As Single
Console.WriteLine("** Program to find all Roots of a Quadration Eqation **")
Console.WriteLine()
Console.Write("Enter the Value of A:- ")
a = Console.ReadLine()
Console.Write("Enter the Value of B:- ")
b = Console.ReadLine()
Console.Write("Enter the Value of C:- ")
c = Console.ReadLine()
Console.WriteLine()
Dim d As Integer = b ^ 2 - 4 * a * c
If d = 0 Then
Console.WriteLine("Roots are real and equal :-")
r1 = -b / (2 * a)
Console.WriteLine("Root1=Root2={0}", r1)
ElseIf d > 0 Then

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 9

Console.WriteLine("Roots are real and Different...")


r1 = (-b + d ^ 0.5) / (2 * a) r2 = (-b - d ^ 0.5) /
(2 * a)
Console.WriteLine("Root1={0},Root2={0}", r1, r2)
Else
Console.WriteLine("Roots are complex and different...")
Console.Write("Root1=")
Console.WriteLine(-b / (2 * a) & "+" & (d * -1) ^ 0.5 / (2 * a) & "i")
Console.Write("Root2=")
Console.WriteLine(-b / (2 * a) & "-" & (d * -1) ^ 0.5 / (2 * a) & "i")
End If
Console.ReadLine()

End Sub

End Module

Output:-

WINDOW Form application

6. 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

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 10

Percentage>=70% : grade C Percentage>=60% : grade C


Percentage>=40% : grade E Percentage<40% : grade

Program Code:--
Public Class Form1
Dim Per As Decimal
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim GrandTotal As Integer = 500
Dim Total As Integer
Total = CInt(TextBox1.Text) + CInt(TextBox2.Text) + CInt(TextBox3.Text) +
CInt(TextBox4.Text) + CInt(TextBox5.Text)
Per = (Total / GrandTotal) * 100
Label8.Text = Per & " % "
Select Case Per
Case 90 To 100
Label9.Text = " A "
Case 80 To 89
Label9.Text = " B "
Case 70 To 79
Label9.Text = " C "
Case 60 To 69
Label9.Text = " D "
Case 40 To 59
Label9.Text = " E "
Case 0 To 39
Label9.Text = " F "
End Select
End Sub

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


Button2.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 11

Label8.Text = " ? "


Label9.Text = " ? "
End Sub End
Class

Output:--

7. Design an application to input basic salary of an employee and Gross salary


according to following:
Basic Salary <=10000 :HRA=20%,DA=80%
Basic Salary <=20000 :HRA=25%,DA=90%
Basic Salary >10000 :HRA=30%,DA=95%

Program Code:---
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim Basic As Integer = CInt(TextBox1.Text)
Dim HRA As Integer

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 12

Dim DA As Integer
Select Case Basic
Case 0 To 10000
TextBox2.Text = CStr(0.2 * Basic)
TextBox3.Text = CStr(0.8 * Basic)
Case 10001 To 20000
TextBox2.Text = CStr(0.25 * Basic)
TextBox3.Text = CStr(0.9 * Basic)
Case 20001 To Integer.MaxValue
TextBox2.Text = CStr(0.3 * Basic)
TextBox3.Text = CStr(0.95 * Basic)
End Select
HRA = CInt(TextBox2.Text)
DA = CInt(TextBox3.Text)
TextBox4.Text = CStr(Basic + HRA + DA)
End Sub

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


Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
End Class

Output:---

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 13

8. Design an application which is similar to login from.

Program Code:--
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Please Enter Username & Password")
ElseIf TextBox1.Text = "Admin" And TextBox2.Text = "Password" Then
MsgBox("Login Success")
Else
MsgBox("Wrong Username & Password")
TextBox1.Text = ""
TextBox2.Text = ""
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
End

End Sub
End Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 14

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 15

9. WAP using checkbox for the following font effects.


Bold
Italic
Underline
Increase font size
Decrease font size
Font color

Program Code:--
Public Class Form1

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


CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Font = New Font(TextBox1.Font, FontStyle.Bold)
End If
If CheckBox1.Checked = False Then
TextBox1.Font = New Font(TextBox1.Font, FontStyle.Regular)
End If
End Sub
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox2.CheckedChanged
If CheckBox2.Checked = True Then
TextBox1.Font = New Font(TextBox1.Font, FontStyle.Italic)
End If
If CheckBox2.Checked = False Then
TextBox1.Font = New Font(TextBox1.Font, FontStyle.Regular)
End If
End Sub
Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox3.CheckedChanged
If CheckBox3.Checked = True Then
TextBox1.Font = New Font(TextBox1.Font, FontStyle.Underline)
End If
If CheckBox3.Checked = False Then

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 16

TextBox1.Font = New Font(TextBox1.Font, FontStyle.Regular)


End If
End Sub
Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox4.CheckedChanged

If CheckBox4.Checked = True Then


TextBox1.Font = New Font(TextBox1.Font, FontStyle.Strikeout)
End If
If CheckBox4.Checked = False Then
TextBox1.Font = New Font(TextBox1.Font, FontStyle.Regular)
End If
End Sub
Private Sub CheckBox8_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox8.CheckedChanged
If CheckBox8.Checked = True Then
TextBox1.ForeColor = Color.Red
End If
If CheckBox8.Checked = False Then
TextBox1.ForeColor = Color.Black
End If
End Sub
Private Sub CheckBox7_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox7.CheckedChanged
If CheckBox7.Checked = True Then
TextBox1.ForeColor = Color.Green
End If
If CheckBox7.Checked = False Then
TextBox1.ForeColor = Color.Black
End If
End Sub
Private Sub CheckBox6_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox6.CheckedChanged
If CheckBox6.Checked = True Then
TextBox1.ForeColor = Color.Blue
End If
If CheckBox6.Checked = False Then
TextBox1.ForeColor = Color.Black
End If
End Sub
Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox5.CheckedChanged
If CheckBox5.Checked = True Then
TextBox1.ForeColor = Color.Purple
End If
If CheckBox5.Checked = False Then
TextBox1.ForeColor = Color.Black
End If
End Sub

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


CheckBox10.CheckedChanged
If CheckBox10.Checked = True Then
TextBox1.Font = New Font(TextBox1.Text, TextBox1.Font.Size + 2)
End If
End Sub

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 17

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


CheckBox9.CheckedChanged
If CheckBox9.Checked = True Then
TextBox1.Font = New Font(TextBox1.Text, TextBox1.Font.Size - 2)
End If
End Sub End
Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 18

10 Design the form that calculate sum Multiplication, division


and Subtraction of to number.

Program Code:---
Public Class Form1
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
Dim a As Integer
Dim b As Integer a =
CInt(TextBox1.Text) b =
CInt(TextBox2.Text)
TextBox3.Text = a * b
End Sub

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


Button1.Click
Dim a As Integer
Dim b As Integer a =
CInt(TextBox1.Text) b =
CInt(TextBox2.Text)
TextBox3.Text = a + b
End Sub

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


Button2.Click
Dim a As Integer
Dim b As Integer a =
CInt(TextBox1.Text) b =
CInt(TextBox2.Text)
TextBox3.Text = a - b
End Sub

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


Button4.Click
Dim a As Integer
Dim b As Integer a =

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 19

CInt(TextBox1.Text) b =
CInt(TextBox2.Text)
TextBox3.Text = a / b
End Sub

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


Button5.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub End
Class

Output:--

Sum Multiplication, division & Subtraction

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 20

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 21

11. Design Simple Calculator.

Program Code:--
Public Class Form1
Dim val1, val2 As Integer
Dim sign As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
TextBox1.Text = TextBox1.Text & 1
End Sub

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


Button2.Click
TextBox1.Text = TextBox1.Text & 2
End Sub

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


Button3.Click
TextBox1.Text = TextBox1.Text & 3
End Sub

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


Button8.Click
TextBox1.Text = TextBox1.Text & 4
End Sub

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


Button7.Click
TextBox1.Text = TextBox1.Text & 5
End Sub

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


Button6.Click
TextBox1.Text = TextBox1.Text & 6

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 22

End Sub

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


Button12.Click
TextBox1.Text = TextBox1.Text & 7
End Sub

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


Button11.Click
TextBox1.Text = TextBox1.Text & 8
End Sub

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


Button10.Click
TextBox1.Text = TextBox1.Text & 9
End Sub

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


Button16.Click
TextBox1.Text = TextBox1.Text & 0
End Sub

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


val1 = TextBox1.Text
TextBox1.Clear()
TextBox1.Focus() sign
= "-"
End Sub

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


val1 = TextBox1.Text
TextBox1.Clear()
TextBox1.Focus() sign
= "*"
End Sub

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


Button13.Click
val1 = TextBox1.Text
TextBox1.Clear()
TextBox1.Focus() sign
= "/"
End Sub

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


Button14.Click val2 = TextBox1.Text
If sign = "+" Then
TextBox1.Text = val1 + val2
ElseIf sign = "-" Then
TextBox1.Text = val1 - val2
ElseIf sign = "*" Then
TextBox1.Text = val1 * val2
Else
TextBox1.Text = val1 / val2
End If
End Sub

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 23

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


Button15.Click
TextBox1.Clear()
TextBox1.Focus()
End Sub

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


val1 = TextBox1.Text
TextBox1.Clear()
TextBox1.Focus() sign
= "+"
End Sub
End Class

Output:-

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 24

12. Design the form to input radius of a circle and find its
circumference and area.

Program Code:--
Public Class Form1

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


Button1.Click
Dim Radius As Decimal = CInt(TextBox1.Text)
Dim Pi As Decimal = 3.14
TextBox2.Text = Pi * (Radius * Radius)
TextBox3.Text = 2 * (Pi * Radius)
End Sub

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


Button2.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
End Sub End
Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 25

13.Design the form to input length in Centimeter and Convert it into


meter.

Program Code:--
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim Cm As Integer
Cm = CInt(TextBox1.Text)
TextBox2.Text = Cm / 100
End Sub

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


Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 26

14. design the form to input temperature in Celsius and convert it into
Fahrenheit.

Program Code:--
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim cel As Decimal
Dim Fran As Decimal cel =
CInt(TextBox1.Text) Fran =
(cel * (9 / 5)) + 32
TextBox2.Text = Fran
End Sub

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


Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub End
Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 27

15. Design the form to input Principal amount, time, Rate and Calculate

Simple interest and compound interest show result information in


msgbox.

Program Code:--
Public Class Form1
Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles
Panel1.Paint

End Sub

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


Button1.Click
Dim p, t As Integer
Dim r As Decimal
Dim Si As Decimal p =
CInt(TextBox1.Text) t =
CInt(TextBox2.Text) r =
CInt(TextBox3.Text)
Si = (p * r * t) / 100
MsgBox("Simple Interest : " & Si)
Dim Amount As Decimal
Dim CI As Decimal
Amount = p * (Math.Pow((1 + r / 100), t))
CI = Amount - p
MsgBox("Compound Interest : " & CI)
End Sub

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


Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub End
Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 28

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 29

16. Design the form and write a program to sort array element in
ascending order.

Program Code:--
Public Class Form1
Dim arr() As Integer = {2, 4, 1, 3, 5}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
ArrayBox.Items.Clear()
Dim i As Integer = 0
For i = 0 To arr.Count - 1
ArrayBox.Items.Add(arr(i))
Next
End Sub

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


Button2.Click
Dim i As Integer = 0
Dim j As Integer = 0
For i = 0 To arr.Count - 1
For j = i + 1 To arr.Count - 1
If arr(i) > arr(j) Then
Dim k As Integer k
= arr(j) arr(j) =
arr(i) arr(i) = k
End If
Next
Next
ArrayBox.Items.Clear()
For i = 0 To arr.Count - 1
ArrayBox.Items.Add(arr(i))
Next
End Sub
End Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 30

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 31

17. Design the form and write a program to insert an element in an


Array.

Program Code:--
Public Class Form1
Dim arr(5) As Integer
Dim i As Integer = 0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
If i < arr.Count - 1 Then
arr(i) = CInt(TextBox1.Text)
ArrayBox.Items.Add(arr(i)) i
+= 1
Else
MsgBox("Array is Full Can't Add More Element!!")
End If
End Sub End
Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 32

18. Design the form and write a program to delete an element from an
array at specified position.

Program Code:--
Public Class Form1
Dim arr() As Integer = {1, 2, 3, 4, 5}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim ArrEnd As Integer = arr.Length - 1
Dim i As Integer = 0
Dim Pos As Integer = CInt(TextBox1.Text)
While i <> Pos
i += 1
End While
While i <> arr.Count - 1
arr(i) = arr(i + 1)
i += 1
End While
ListBox1.Items.Clear()
ReDim Preserve arr(arr.Length - 2)
Dim j As Integer = 0
For j = 0 To arr.Length - 1
ListBox1.Items.Add(arr(j))
Next
End Sub

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


Dim i As Integer = 0
ListBox1.Items.Clear()
For i = 0 To arr.Length - 1
ListBox1.Items.Add(arr(i))
Next
End Sub
End Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 33

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 34

19. Design the from and write a program to print all unique element in
the array.

Program Code:--
Public Class Form1
Dim arr() As Integer = {9, 9, 8, 1, 3, 6, 9, 7, 1, 2}

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


Button1.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 0 To arr.Length - 1
ListBox1.Items.Add(arr(i))
Next
End Sub

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


Button2.Click
ListBox2.Items.Clear()
Dim i As Integer
Dim j As Integer
For i = 0 To arr.Length - 1
Dim flag As Boolean = False
For j = 0 To arr.Length - 1
If arr(i) = arr(j) And i <> j Then
flag = True
End If
Next
If flag = False Then
ListBox2.Items.Add(arr(i))
End If
Next
End Sub
End Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 35

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 36

20. Design a form to check whether a number is prime Or not using input
box and msgbox.

Program Code:--
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim i As Integer
Dim num As Integer = CInt(TextBox1.Text)
Dim f As Boolean = False
For i = 2 To num - 1
If num Mod i = 0 Then
TextBox2.Text = "Not a Prime"
f = True Exit For
End If
Next
If f = False Then
TextBox2.Text = "Prime Number"
End If
End Sub
End Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 37

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 38

21. Write a program to print Fibonacci series up to n terms.

Program Code:--
Public Class Form1
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
TextBox1.Text = ""
ListBox1.Items.Clear()
End Sub
Public Function GetFib(ByVal n As Integer) As Integer
ListBox1.Items.Clear()
Dim a, b, c As Integer
Dim i As Integer a = 0
b = 1
ListBox1.Items.Add(a)
ListBox1.Items.Add(b)
For i = 1 To n - 2
ListBox1.Items.Add(a + b)
c = a + b a = b
b = c n -= 1 Next
Return 0
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim n As Integer = CInt(TextBox1.Text)
GetFib(n)
End Sub
End Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 39

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 40

22. Design the following form when user clicks on Radio Button then select
Checkbox.

Program Code:--
Public Class Form1
Dim gen As Boolean = False
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs)
Handles RadioButton3.CheckedChanged
If gen = True And RadioButton3.Checked = True Then
CheckBox1.Checked = True
CheckBox3.Checked = False
CheckBox2.Checked = False
End If
End Sub

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


Handles RadioButton1.CheckedChanged
gen = True
End Sub

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


Handles RadioButton2.CheckedChanged
gen = True
End Sub

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


Handles RadioButton4.CheckedChanged
If gen = True And RadioButton4.Checked = True Then
CheckBox1.Checked = False
CheckBox3.Checked = False
CheckBox2.Checked = True
End If
End Sub

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


Handles RadioButton5.CheckedChanged
If gen = True And RadioButton5.Checked = True Then
CheckBox1.Checked = False
CheckBox3.Checked = True

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 41

CheckBox2.Checked = False
End If
End Sub

End Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 42

23. Design the Digital watch using Timer Control.

Program Code:--
Public Class Form1

Dim hh, mm, ss As Integer

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


Button3.Click
Label1.Text = "23"
Label3.Text = "59"
Label5.Text = "00"
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


hh = Val(Label1.Text) mm = Val(Label3.Text) ss = Val(Label5.Text)
ss = ss + 1 If ss = 60 Then ss = 0 mm = mm + 1
End If
If mm = 60 Then
mm = 0 hh =
hh + 1
End If
If hh = 24 Then
hh = 1
End If
Label1.Text = Format(hh, "00")
Label3.Text = Format(mm, "00")
Label5.Text = Format(ss, "00")
End Sub

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


Button2.Click
Timer1.Enabled = False
End Sub

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


Button1.Click
Timer1.Enabled = True
End Sub
End Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 43

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 44

24. Design the following form using horizontal scrollbar. In this, when user click
on particular scrollbar then back color of shape will be changed to Red, Green &
Blue color.

Program Code :--


Public Class Form1
Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles
HScrollBar1.Scroll
Panel1.BackColor = Color.Red
End Sub
Private Sub HScrollBar2_Scroll(sender As Object, e As ScrollEventArgs) Handles
HScrollBar2.Scroll
Panel2.BackColor = Color.Blue
End Sub
Private Sub HScrollBar3_Scroll(sender As Object, e As ScrollEventArgs) Handles
HScrollBar3.Scroll
Panel3.BackColor = Color.Green
End Sub
End Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 45

25. Design the following form using vertical scrollbar. In this, when
user click on particular scrollbar then back color of shape will be
changed to Red, Green &Blue color.

Program Code:--
Public Class Form1
Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles
VScrollBar1.Scroll
Panel1.BackColor = Color.Red
End Sub
Private Sub VScrollBar2_Scroll(sender As Object, e As ScrollEventArgs) Handles
VScrollBar2.Scroll
Panel1.BackColor = Color.Green
End Sub
Private Sub VScrollBar3_Scroll(sender As Object, e As ScrollEventArgs) Handles
VScrollBar3.Scroll
Panel1.BackColor = Color.Blue
End Sub

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


Button1.Click
End
End Sub
End Class

Output:-- red

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 46

Green

Blue

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 47

26. Design the form with different controls.

Program Code:--
Public Class Form1
Dim msg As String
Dim accessories As String
Dim process As String
Dim Os As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox1.CheckedChanged

If CheckBox1.Checked = True Then


accessories = accessories + CheckBox1.Text & ","
ElseIf CheckBox1.Checked = False Then
accessories = accessories.Replace("Printer,", "")
End If
End Sub
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox2.CheckedChanged
If CheckBox2.Checked = True Then
accessories = accessories + CheckBox2.Text & ","
ElseIf CheckBox2.Checked = False Then
accessories = accessories.Replace("Modem,", "")
End If
End Sub
Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox4.CheckedChanged

If CheckBox4.Checked = True Then


accessories = accessories + CheckBox4.Text & ","
ElseIf CheckBox4.Checked = False Then
accessories = accessories.Replace("Moniter,", "")
End If
End Sub
Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 48

CheckBox3.CheckedChanged
If CheckBox3.Checked = True Then
accessories = accessories + CheckBox3.Text & ","
ElseIf CheckBox3.Checked = False Then
accessories = accessories.Replace("NIC,", "")
End If
End Sub

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


Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
process = "Pentium 1" Else
process = ""
End If
End Sub

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


Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
process = "Pentium 2" Else
process = ""
End If
End Sub

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


Handles RadioButton3.CheckedChanged
If RadioButton3.Checked = True Then
process = "Pentium 3" Else
process = ""
End If
End Sub

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


Handles RadioButton4.CheckedChanged
If RadioButton4.Checked = True Then
Os = "Windows 98"
Else
Os = ""
End If
End Sub

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


Handles RadioButton6.CheckedChanged
If RadioButton6.Checked = True Then
Os = "Windows NT"
Else
Os = ""
End If
End Sub

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


msg = "You selected a " & process & " With " & Os & " And accesories " &
accessories
TextBox1.Text = msg
End Sub

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 49

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


Button3.Click
End
End Sub

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


Button2.Click accessories = "" msg = "" process
= ""
Os = ""
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
RadioButton6.Checked = False
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
TextBox1.Text = msg
End Sub End
Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 50

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 51

27. Write a program for exception handling of throwing an exception


when dividing by zero condition occur during arithmetic operation.
Program Code:-
Imports System

Module Program
Public Sub Divide(ByVal a As Integer, ByVal b As Integer)
Dim result As Decimal
Try
result = a / b
Catch ex As Exception
Console.WriteLine(" This IS Exception ---->>) {0}", ex)
Console.ReadLine()
Finally
Console.WriteLine("Result : {0}", result)
Console.ReadLine()
End Try
End Sub

Sub Main(args As String())


Dim a As Integer = Console.ReadLine()
Dim b As Integer = Console.ReadLine()
Divide(a, b)
End Sub End
Module

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 52

28. WAP in vb.net such that throw a user define exception when
Temperature is
Zero

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim num As Integer = CInt(Label2.Text)
num += 1 Label2.Text = num
If num = 0 Then
MsgBox("Tempreture is 0 :-)", 48)
End If
End Sub

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


Button2.Click
Dim num As Integer = CInt(Label2.Text)
num -= 1 Label2.Text = num
If num = 0 Then
MsgBox("Tempreture is 0 :-)", 48)
End If
End Sub
End Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 53

Output:-

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 54

29. Design form that show the functionality of listbox

Public Class Form1


Private Sub Button5_Click(sender As Object, e As EventArgs) Handles
Button5.Click
Dim item As String
item = InputBox("Enter Value : ")
ListBox1.Items.Add(item)
End Sub

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


Button6.Click
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub

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


Button7.Click
ListBox1.Items.Clear()
ListBox2.Items.Clear()
End Sub

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


Button8.Click
ListBox1.Sorted = True
ListBox2.Sorted = True
End Sub

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


Button1.Click
If ListBox1.SelectedItem = "" Then
MsgBox("You did't select any item!!")
Else
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End If
End Sub

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


Button2.Click
ListBox2.Items.AddRange(ListBox1.Items)
ListBox1.Items.Clear()

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 55

End Sub

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


Button3.Click
If ListBox2.SelectedItem = "" Then
MsgBox("You did't select any item!!")
Else
ListBox1.Items.Add(ListBox2.SelectedItem)
ListBox2.Items.RemoveAt(ListBox2.SelectedIndex)
End If
End Sub

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


Button4.Click
ListBox1.Items.AddRange(ListBox2.Items)
ListBox2.Items.Clear()
End Sub End
Class

Output:-

Add Value

Move >

All move

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 56

Remove value

Sort

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 57

30.Write a vb.net program to show data in data Grid view.

Program code:-
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Me.DataGridView1.Rows.Add(TextBox1.Text, TextBox2.Text)
End Sub End
Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 58

31.Create following table Student(id,name,course,DOB,address) Write vb.net


application to
1. Add records
2. View all the records

Program Code:-
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim n As Integer
Sub Pross()
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\DotNet\Q_31_Student.accdb")
con.Open()
Dim adp As New OleDbDataAdapter("select * from Student", con)
Dim ds As New DataSet adp.Fill(ds, "Student") n =
ds.Tables("Student").Rows.Count con.Close()
End Sub

Sub ShowGrid()
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\DotNet\Q_31_Student.accdb")
con.Open()
Dim adp As New OleDbDataAdapter("select * from Student", con)
Dim ds As New DataSet adp.Fill(ds, "Student")
DataGridView1.DataSource = ds.Tables("Student")
con.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or
TextBox4.Text = "" Then
MsgBox("Empty Fields !!")

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 59

Else
Pross()
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\DotNet\Q_31_Student.accdb")
con.Open()
Dim cmd As New OleDbCommand()
cmd.Connection = con cmd.CommandType
= CommandType.Text
cmd.CommandText = "insert into Student values (" & n + 1 & ",'" &
TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" &
TextBox4.Text & "')" cmd.ExecuteNonQuery()
con.Close()
MsgBox("Record Saved Succesfully!!!")
End If
End Sub

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


Button2.Click
ShowGrid()
End Sub

End Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 60

32. Develop a project which display the student information in the


relevant fields from the database which already exists.

Program Code:--
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\jatin\Documents\Q32_Database.accdb")
Dim Index As Integer = 0
Dim table As New DataTable()

Public Sub ShowData(Position As Integer)


Dim cmd As New OleDbCommand("select * from Student", con)
Dim adp As New OleDbDataAdapter(cmd)
adp.Fill(table)
TextBox1.Text = table.Rows(Position)(0).ToString()
TextBox2.Text = table.Rows(Position)(1).ToString()
TextBox3.Text = table.Rows(Position)(2).ToString()
TextBox4.Text = table.Rows(Position)(3).ToString()
End Sub

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


Button1.Click
Index = 0
ShowData(Index)
End Sub

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


Button2.Click
If Index = table.Rows.Count - 1 Then
MsgBox("Last Record Reached!!!")
Else
Index += 1
ShowData(Index)
End If
End Sub

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 61

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


Button3.Click
If Index <> 0 Then
Index -= 1
ShowData(Index)
Else
MsgBox("First Record Reached!!")
End If
End Sub

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


Button4.Click
Index = 0
Index = table.Rows.Count - 1
ShowData(Index)
End Sub

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


Button5.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = "" con.Close()
End Sub
End Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 62

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 63

33. Define structure student. Structure student has data members for
storing name, rollno ,name of three subjects and marks. Write member
function to store and print data. Program Code:--
Imports System

Module Program
Structure Student
Dim name As String
Dim roll As Integer
Dim NameOfSub() As String
Dim Marks() As Integer
Sub GetData()
Console.WriteLine("Enter Student Name : ")
name = Console.ReadLine()
Console.WriteLine("Enter Roll Num : ")
roll = Console.ReadLine() ReDim
Preserve NameOfSub(2)
ReDim Preserve Marks(2)
Dim i As Integer
For i = 0 To NameOfSub.Length - 1
Console.WriteLine("Enter Subject " & i + 1 & " : ")
Dim subName As String = CStr(Console.ReadLine())
NameOfSub(i) = subName
Next
For i = 0 To Marks.Length - 1
Console.WriteLine("Enter Marks of Sub " & i + 1 & " : ")
Marks(i) = Console.ReadLine()
Next
End Sub
Sub Print()
Console.WriteLine("Student Name : " & name)
Console.WriteLine("Student Roll : " & roll)
Dim i As Integer
For i = 0 To NameOfSub.Length - 1
Console.WriteLine("Subjects : " & NameOfSub(i) & " ")
Next
For i = 0 To Marks.Length - 1
Console.WriteLine("Marks Of " & NameOfSub(i) & " : " & Marks(i) & "
")
Next
End Sub
End Structure
Sub Main()
Dim st As New Student
st.GetData() st.Print()
End Sub
End Module

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 64

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 65

34. Write a class having name Calculate that uses static overloaded function to
calculate area of circle, area of rectangle and area of triangle.

Program Code:--

Public Class Form1

Public Class Calculate

Public Function Area(ByVal r As Decimal) As Decimal


'area of circle
Return (3.14 * r * r)
End Function

Public Function Area(ByVal val As Decimal, ByVal b As Decimal, ByVal h As


Decimal) As Decimal
'area of triangle
Return (val * b * h)
End Function

Public Function Area(ByVal i As Decimal, ByVal b As Decimal) As Decimal


'area of rectangle
Return (i * b)
End Function

End Class

Dim b As Decimal, r As Decimal, i As Decimal, h As Decimal


Dim val As Decimal = 0.5
Dim ch As Integer

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


Button3.Click
Dim obj As New Calculate() i
= InputBox("Enter The Value of l") b
= InputBox("Enter The Value of b")
TextBox1.Text = obj.Area(i, b)
End Sub

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

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 66

Button1.Click
Dim obj As New Calculate() r
= InputBox("Enter The Value of R")
TextBox1.Text = obj.Area(r)
End Sub

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


Button2.Click
Dim obj As New Calculate() b
= InputBox("Enter The Value of b") h
= InputBox("Enter The Value of h")
TextBox1.Text = obj.Area(val, b, h)
End Sub
End
Class

Output:--

Circle

Triangle

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 67

Rectangle

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 68

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 69

35. WAP to check whether a given number is neon or not using user
define function.

Program Code:---
Public Class Form1

Public Function CheckNeon(ByVal Num As Integer) As Boolean


Dim Square As Integer = Num * Num
Dim DummySquare = Square
Dim NewNumber As Integer = 0
While (DummySquare > 0)
NewNumber = NewNumber + DummySquare Mod 10
DummySquare = DummySquare \ 10
End While
NewNumber = CInt(NewNumber)
Num = CInt(Num)
If Num = NewNumber Then
Return True
Else
Return False
End If

End Function

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


Button1.Click
Dim Num As Integer = TextBox1.Text
Dim Ans As Boolean = CheckNeon(Num)
TextBox2.Text = Ans
End Sub

End
Class

Output:---

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 70

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 71

36. WAP to check whether a given number is Niven or not using


procedure.

Program Code:--
Public Class Form1

Public Sub CheckNiven(ByVal Num As Integer)


Dim Square As Integer = Num * Num
Dim DummySquare = Square
Dim NewNumber As Integer = 0
If (Num < 9) Then
TextBox2.Text = True
NewNumber = Num
Else
While (DummySquare > 0)
NewNumber = NewNumber + DummySquare Mod 10
DummySquare = DummySquare \ 10
End While
End If

NewNumber = CInt(NewNumber)
Num = CInt(Num)
If Num Mod NewNumber = 0 Then
TextBox2.Text = True
Else
TextBox2.Text = False
End If

End Sub

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


Button1.Click
Dim Num As Integer = TextBox1.Text
CheckNiven(Num)
End Sub
End
Class

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 72

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 73

37. WAP to check whether a given number is Duck number or


not .

Program Code:--
Public Class Form1
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

End Sub

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


Button1.Click
Dim Num As String
Num = TextBox1.Text

If Num.StartsWith("0") Then
TextBox2.Text = False
ElseIf Num.Contains("0") Then
TextBox2.Text = True
Else
TextBox2.Text = False
End If

End Sub End


Class

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 74

38. WAP to check whether a given number is Spy number or not


.
Program Code:--
Imports System

Module Program
Sub Main(args As String())
Console.WriteLine("Enter The value of Num : ")
Dim Num As Integer = Console.ReadLine()
Dim Sum As Integer = 0
Dim Mul As Integer = 1
Dim Remain As Integer
Dim DummyNum As Integer = Num

While (DummyNum <> 0)


Remain = DummyNum Mod 10
Sum = Sum + Remain
Mul = Mul * Remain
DummyNum = DummyNum \ 10
End While

If Sum = Mul Then


Console.WriteLine("Num is Spy Number : " & Num)
Else
Console.WriteLine("Num is not a Spy Number : " & Num)
End If

End Sub End


Module

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 75

39. Write a program to find first and last digit of any number.
Program Code:--
Imports System

Module Program
Sub Main(args As String())
Dim Num As Integer
Console.WriteLine("Enter The Value of Num")
Num = Console.ReadLine()
Dim NewNum As Integer = Num
Dim First As Integer
Dim Last As Integer
Last = NewNum Mod 10
NewNum = NewNum \ 10
Dim remain As Integer
While (NewNum <> 0)
remain = NewNum Mod 10
NewNum = NewNum \ 10
End While
First = remain
Console.WriteLine("First Digit of Num : " & First & " Last Digit of Num : "
& Last)
End Sub
End Module

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 76

40. Write a program to enter any number and print its reverse.
Program Code:--
Imports System

Module Program
Sub Main(args As String())
Dim Num As Integer
Console.WriteLine("Enter Value Of Num : ")
Num = Console.ReadLine()
Dim Remain As Integer
Dim Reverse As Integer = 0
Dim DummyNum As Integer = Num
While (DummyNum <> 0)
Remain = DummyNum Mod 10
Reverse = Reverse * 10 + Remain
DummyNum = DummyNum \ 10
End While

Console.WriteLine("Num is " & Num & " And Its Reverse is " & Reverse)
End Sub
End Module

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 77

41. WAP to check whether a given number is Armstrong number or not.


Program Code:--
Imports System

Module Program
Sub Main(args As String())
Dim Num As Integer
Console.WriteLine("Enter The Value Of Num : ")
Num = Console.ReadLine()
Dim Sum As Integer = 0
Dim NewNum As Integer = Num
Dim Remain As Integer
While (NewNum <> 0)
Remain = NewNum Mod 10
Sum = Sum + Remain * Remain * Remain
NewNum = NewNum \ 10
End While

If Sum = Num Then


Console.WriteLine("Both The " & Num & " And " & Sum & " Is Same So its is
an Armstrong Number")
Else
Console.WriteLine("Both The " & Num & " And " & Sum & " Is Not Same So
its is Not an Armstrong Number")
End If

End Sub End


Module

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 78

42. WAP to enter any number and check whether the no. is palindrome or
not.

Program Code:--
Imports System

Module Program
Sub Main(args As String())
Dim Num As Integer
Console.WriteLine("Enter The Value Of Num : ")
Num = Console.ReadLine()
Dim DummyNum As Integer = Num
Dim Rev As Integer = 0
Dim Remain As Integer

While (DummyNum > 0)


Remain = DummyNum Mod 10
Rev = Rev * 10 + Remain
DummyNum = DummyNum \ 10
End While

If Num = Rev Then


Console.WriteLine("YES! It is a Palindrome")
Else
Console.WriteLine("NO! It is Not a Palindrome")
End If
End Sub End
Module

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 79

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 80

43. WAP to calculate factorial of a number using user define procedure.


Program Code:--
Imports System

Module Factorial
Sub main()
Dim i, n, F As Integer
F = 1
System.Console.WriteLine("Enter Number to find Factorial:-")
n = System.Console.ReadLine()
For i = 1 To n
F = F * i

Next
System.Console.WriteLine("Factorial of " & n & " is " & F)
System.Console.ReadLine()

End Sub

End Module

Output:--

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 81

44. Create a class circle with data member radius; provide member
function to calculate area. Define a class sphere from class circle,
provide member function to calculate area class cylinder from class
sphere with additional data member for height and member function to
calculate volume.

Program Code:--
Imports System
Imports System.Runtime.CompilerServices

Module Program
Class circle
Public radius As Integer
Sub area(ByVal r As Integer)
radius = r
Console.WriteLine("Circle class")
Console.Write("Area of Circle :- ")
Console.WriteLine(Math.PI * radius * radius)
End Sub
End Class
Class sphere
Inherits circle
Sub display()
Console.WriteLine("sphere class")
Console.Write("Area of Sphere :- ")
Console.WriteLine(Math.PI * radius * radius * 4)
End Sub
End Class
Class cylinder
Inherits sphere
Sub display2(ByVal h1 As Integer)
Dim h As Integer = h1
Console.WriteLine("Cylinder Class")
Console.Write("Volume of Cylinder :- ")
Console.WriteLine(Math.PI * radius * h)
End Sub
End Class
Sub main()
Dim obj As cylinder = New cylinder()
obj.area(5) obj.display()
obj.display2(6) Console.ReadLine()
End Sub
End Module

Nikhil Jaiswal BCA 3rd


VB.NET Assignment Page 82

Output:--

Nikhil Jaiswal BCA 3rd

You might also like