Vb.net Program
Vb.net Program
Imports System
Module Program
Sub Main(args As String())
Console.WriteLine("Hello World!")
End Sub
End Module
OUTPUT
Program to Demonstrate Add Two Numbers
Imports System
Module Addition
Sub Main()
Dim Num1, Num2, sum As Integer
Console.WriteLine("Enter the first Number :")
Num1 = Console.ReadLine()
Console.WriteLine("Enter the second Number :")
Num2 = Console.ReadLine()
sum = Num1 + Num2
Console.WriteLine("The sum is :" & sum)
Console.ReadLine()
End Sub
End Module
Program to Demonstrate Variable Declaration.
Imports System
Module Program
Sub Main()
Dim intData As Integer
Dim CharData As Char
Dim strData As String
Dim dblData As Double
Dim single_data As Single
intData = 10
CharData = "A"
strData = " VB.NET is a Programming Language."
dblData = 4567.676
single_data = 23.08
OUTPUT
Program to Demonstrate Variable Form User.
Imports System
Module Program
Sub Main()
Dim num As Integer
Dim name As String
Dim age As Double
Console.WriteLine("Enter your favourite
Number:")
num = Console.ReadLine()
Console.WriteLine("Write your Good name:")
name = Console.ReadLine()
Console.WriteLine("What is your age:")
age = Console.ReadLine()
Console.WriteLine("Your Favourite number
is {0}", num)
Console.WriteLine("Your Good name is {0}",
name)
Console.WriteLine("Your age is {0}", age)
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to Demonstrate Use of Local variable.
Imports System
Module Program
Sub Main()
Console.WriteLine("Hello User!")
Console.WriteLine(" Scope of local varibale within a
function")
local()
local2()
Console.WriteLine("press any key to exit...")
Console.ReadKey()
End Sub
Sub local()
Dim X As Integer
' declaration of local variable
X = 50
Console.WriteLine(" Value of Local value X is {0}", X)
End Sub
Sub local2()
Dim X As String
' scope of local variable within a function
X = "60"
Console.WriteLine(" Value of X is {0}", X)
End Sub
End Module
OUTPUT
Program to Demonstrate Arithmetical Operators.
Imports System
Imports System.Security.Cryptography.X509Certificates
Module Arthmeticaloperators
Sub Main()
Dim a, b, c As Integer
Dim p As Double = 2
Console.WriteLine(" Enter the value of a:")
a = Console.ReadLine()
Console.WriteLine("Enter the value of b:")
b = Console.ReadLine
c=a +b
Console.WriteLine("The sum of a+b is {0}", c)
c=a -b
Console.WriteLine("The difference of a-b is {0}", c)
c=a *b
Console.WriteLine("The Product of a*b is {0}", c)
c=a /b
Console.WriteLine("The quotient of a\b is{0}", c)
c = a Mod b
Console.WriteLine("The Modolus of a Mod b is {0}", c)
c=a ^p
Console.WriteLine("The power of a^p is {0}", c)
Console.WriteLine("Preas any key to exit")
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to Demonstrate Comparision Operators.
Imports System
Module comparision_operators
Sub Main()
Dim A As Integer
Dim B As Integer
Dim Result, obj1, obj2 As Object
Dim str1, str2 As String
Console.WriteLine("Enter the value of A: ")
A = Console.ReadLine()
Console.WriteLine("Enter the value of B: ")
B = Console.ReadLine()
Console.WriteLine("Enter the value of obj1: ")
obj1 = Console.ReadLine()
Console.WriteLine("Enter the value of obj2: ")
obj2 = Console.ReadLine()
Console.WriteLine("Enter the value of str1: ")
str1 = Console.ReadLine()
Console.WriteLine("Enter the value of str2: ")
str2 = Console.ReadLine()
Console.WriteLine(" Output of A > B is {0}", A > B)
Console.WriteLine(" Output of A < B is {0}", A < B)
Console.WriteLine(" Output of A = B is {0}", A = B)
Console.WriteLine(" Output of A <> B is {0}", A <> B)
Console.WriteLine(" Output of A >= B is {0}", A >= B)
Console.WriteLine(" Output of A <= B is {0}", A <= B)
Result = obj1 Is obj2
Console.WriteLine(" Output of obj Is obj2 is {0}", Result)
Result = obj1 IsNot obj2
Console.WriteLine(" Output of obj IsNot obj2 is {0}",
Result)
Result = str1 Like str2
Console.WriteLine(" Output of str Like str2 is {0}", Result)
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module
Program to Demonstrate Logical Bitwise Operators.
Imports System
Imports System.Collections.Specialized
Module Logical_Bitwise
Sub Main()
Dim A, B, Result As Boolean
Console.WriteLine("Enter the value fo A: ")
A = Console.ReadLine()
Console.WriteLine("Ente the value for B: ")
B = Console.ReadLine()
Result = A And B
Console.WriteLine("And operator{0}", Result)
Result = A Or B
Console.WriteLine("Or Operator{0}", Result)
Result = Not A
Console.WriteLine("Not of A{0}", Result)
Result = Not B
Console.WriteLine("Not of B{0}", Result)
Result = A Xor B
Console.WriteLine("Xor operator{0}", Result)
Result = A AndAlso B
Console.WriteLine("AndAlso Operator{0}", Result)
Result = A OrElse B
Console.WriteLine("OrElse Operator{0}", Result)
Imports System
Module Bit_shift_operator
Sub Main()
Dim X, Y, Z As Double
Console.WriteLine("Enter value of X: ")
X = Console.ReadLine()
Console.WriteLine("Enter value of y: ")
Y = Console.ReadLine()
Z = X And Y
Console.WriteLine("And operator is {0}", Z)
Z = X Or Y
Console.WriteLine("Or operator is {0}", Z)
Z = X Xor Y
Console.WriteLine("Xor operator is {0}", Z)
Z = Not X
Console.WriteLine("Not of X is {0}", Z)
Z = Not Y
Console.WriteLine("Not of Y is {0}", Z)
Console.WriteLine("The left bit shift operaator
X<<1={0}", X << 1)
Console.WriteLine("The lift shift operator
Y<<1={0}", Y << 1)
Console.WriteLine("The right shift operator
X>>1={0}", X >> 1)
Console.WriteLine("The right shift operator
Y>>1={0}", Y >> 1)
Imports System
Module Program
Sub Main()
Dim A, B, c As Integer
c=2
Dim Str1, Str2 As String
Console.WriteLine("Enter value for A: ")
A = Console.ReadLine()
Console.WriteLine("Enter Str1: ")
Str1 = Console.ReadLine()
Console.WriteLine("Enter Str2: ")
Str2 = Console.ReadLine()
B=A
Console.WriteLine("Assign Value of A to B is
B={0}", B)
B += A
Console.WriteLine("Add and assign value of A to B
is B={0}", B)
B -= A
Console.WriteLine("Subtract and assign value of A
to B is B={0}", B)
B *= A
Console.WriteLine("Multiply and aasign value of A
to B is B={0}", B)
B \= A
Console.WriteLine("Divide and assighn value of A
to B is B={0}", B)
B ^= c
Console.WriteLine("Raise the power C to B is
B={0}", B)
Str1 &= Str2
Console.WriteLine("Conatenate string Str1 and
Str2{0}", Str1)
Console.WriteLine("Press any key to exit")
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to Demonstrate Concatenation Operators.
Imports System
Module Program
Sub Main()
Dim str, str2, str3, str4, result, result2 As String
Console.WriteLine("Write str1:")
str = Console.ReadLine()
Console.WriteLine("Write str2:")
str2 = Console.ReadLine()
Console.WriteLine("Write str3:")
str3 = Console.ReadLine()
Console.WriteLine("Write str4:")
str4 = Console.ReadLine()
Imports System
Module Data_Types
Sub Main()
Console.WriteLine("This Program is developed to
show different Data types in VB.NET")
Dim Str As String
Dim get_date As Date
Dim c As Char
Dim Num As Byte
Dim Num1 As Single
Dim Num2 As Double
Str = "HELLO AND WELLCOME TO MY PROGRAM"
c = "A"
Num = 1
Console.WriteLine("Enter Today's date")
get_date = Console.ReadLine()
Console.WriteLine("Enter value for Num1:")
Num1 = Console.ReadLine()
Console.WriteLine("Enter value for Num2:")
Num2 = Console.ReadLine()
Console.WriteLine("String MSG is:{0} ", Str)
Console.WriteLine("Date:{0}", get_date)
Console.WriteLine("character is:{0}", c)
Console.WriteLine("Byte is:{0}", Num)
Console.WriteLine("Single is:{0}", Num1)
Console.WriteLine("Double is:{0}", Num2)
Console.WriteLine("Press any key to exit")
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to Demonstrate If Condition.
Imports System
Module If_condition
Sub Main()
Dim a As Integer
Console.WriteLine("This is an if condition
program")
Console.WriteLine("Enter the value of A ")
a = Console.ReadLine
If (a > 8) Then
Console.WriteLine("a is greater")
End If
Console.WriteLine("Press any key to exit")
End Sub
End Module
Program to Demonstrate If Then Else Condition.
Imports System
Module Program
Sub Main()
Dim A As Integer
A = 30
Console.WriteLine("This is an IF THEN ELSE
PROGRAM")
Console.WriteLine("Enter the value of A ")
A = Console.ReadLine
If (A < 21) Then
Console.WriteLine("A is greater")
Else
Console.WriteLine("A is not greatest")
End If
Console.ReadKey()
End Sub
End Module
Program to Demonstrate If Then Else Condition.
Imports System
Module Program
Sub Main()
Dim A As Integer
A = 30
Console.WriteLine("This is an IF THEN ELSE
PROGRAM")
Console.WriteLine("Enter the value of A ")
A = Console.ReadLine
If (A < 21) Then
Console.WriteLine("A is greater")
Else
Console.WriteLine("A is not greatest")
End If
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to Demonstrate ElseIf Condition.
Imports System
Module elseif_statement
Sub Main()
Console.WriteLine("This is an elseif conditional
statement program")
Dim a, b, c As Integer
a = 10
b = 20
c = 30
If (a > b) Then
If (a > c) Then
Console.WriteLine("a is greatest")
Else
Console.WriteLine("c is greatet")
End If
Else
If (b > c) Then
Console.WriteLine("b is greatest")
Else
Console.WriteLine("c is greatest")
End If
End If
Console.WriteLine("Press any key to exit")
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to Demonstrate If Then ElseIf Condition.
Imports System
Imports System.Reflection.PortableExecutable
Module If_elseif
Sub Main()
Dim Maths, English, SocialScience, Science,
Hindi, per As Integer
Console.WriteLine("This program is to
demonstrate If then Elseif statement")
Console.WriteLine("Enter the marks of student in
Five subjects:")
Maths = Console.ReadLine()
English = Console.ReadLine()
SocialScience = Console.ReadLine()
Science = Console.ReadLine()
Hindi = Console.ReadLine()
per = (Maths + English + SocialScience + Science + Hindi) / 5
OUTPUT
Program to Demonstrate If Condition in Form.
OUTPUT
Program to Demonstrate Switch Condition in Form.
End Select
End Sub
End Class
OUTPUT
Program to Demonstrate For Next Loop.
Imports System.Drawing.Imaging
Public Class Form1
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click
Dim num, sum As Integer
num = 10
For num = 1 To 10
sum = sum + num
MsgBox(sum)
Next
End Sub
End Class
OUTPUT
Program to Demonstrate Do Loop.
Imports System
Module Program
Sub Main(args As String())
Console.WriteLine("Program to display N natural
numbers ")
Dim num As Integer
Dim i As Integer = 1
Console.WriteLine("Enter value of your choice: ")
num = Console.ReadLine()
Do While (i <= num)
Console.WriteLine(i)
i=i+1
Loop
Console.ReadLine()
End Sub
End Module
OUTPUT
Program to Demonstrate Do While Loop.
Imports System
Imports System.Linq.Expressions
Module Program
Sub Main(args As String())
Console.WriteLine("Program to display sum of N
natural numbers")
Dim num As Integer
Dim i As Integer
Dim sum As Integer
i=1
sum = 0
Console.WriteLine("Enter value of your choice ")
num = Console.ReadLine()
Console.WriteLine("Values are: ")
Do
sum = sum + i
i=i+1
Console.WriteLine(i)
Loop While (i <= num)
Console.WriteLine("Sum is : {0}", sum)
Console.ReadLine()
End Sub
End Module
OUTPUT
Program to Create Mathematical Table
Imports System
Module Program
Sub Main(args As String())
Console.WriteLine("Program to display table using
For Next Loop")
Dim num, i As Integer
i=1
Console.WriteLine("Enter the number to print the
table: ")
num = Console.ReadLine()
Console.WriteLine("Table of ")
For i = 1 To 20
Console.WriteLine(num & "*" & i & "=" & i *
num)
Next
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to find even and odd numbers Using
While Loop
Imports System
Imports System.ComponentModel.Design
Module Program
Sub Main(args As String())
Console.WriteLine("Program to find even and odd
numbers")
Dim num, i As Integer
i=1
Console.WriteLine("enter the value for num: ")
num = Console.ReadLine()
While i <= num
If (i Mod 2 = 0) Then
Console.WriteLine("{0} is even number", i)
Else
Console.WriteLine("{0} is odd number", i)
End If
i=i+1
End While
Console.ReadLine()
End Sub
End Module
OUTPUT
Program to find First N Natural Numbers
i=i+1
MsgBox(i)
Next
End Sub
Private Sub Button1_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Me.Load
Button1.Text = ""
End Sub
End Class
OUTPUT
Program to Demonstrate Arrays
Public Class Form1
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click
Dim markList(10) As Double
Dim marks As Double
Dim i As Integer
marks = 85.5
For i = 0 To 10
markList(i) = marks
marks = marks + 2.5
Next
For i = 0 To 10
MsgBox(markList(i))
Next
End Sub
End Class
OUTPUT
Program to Demonstrate Arrays Numbers
Imports System.Drawing.Drawing2D
Imports System.Security.Policy
Public Class Form1
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click
Dim Matrix(,) As Integer = {{1, 2}, {3, 4}, {5, 6}}
Dim i, j As Integer
For i = 0 To 2
For j = 0 To 1
MsgBox(Matrix(i, j),)
Next j
Next i
End Sub
End Class
OUTPUT
Program to Demonstrate Arrays Class
OUTPUT
1
Program to Demonstrate Sub Procedure
Imports System
Module Program
Sub Main()
Console.WriteLine("Creating a Sub Procedure")
DemoProcedure()
End Sub
Sub DemoProcedure()
Console.WriteLine("I am using sub Procedure in
Vb.Net")
Console.WriteLine("Press any key to Exit")
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to find Maximum among two numbers using
functions
Imports System
Imports
System.Security.Cryptography.X509Certificates
Module Program
Sub Main()
Console.WriteLine("Program to find Maximum
among two numbers using functions")
Dim a, b As Integer
Console.WriteLine("Enter the value of a: ")
a = Console.ReadLine()
Console.WriteLine("Enter the value of a: ")
b = Console.ReadLine
Dim max As Integer = FindMax(a, b)
Console.WriteLine("The largest number is {0} ",
max)
Console.WriteLine("Press any key to exit")
End Sub
Function FindMax(ByVal num1 As Integer, ByVal
num2 As Integer) As Integer
Dim Result As Integer
If (num1 > num2) Then
Result = num1
Else
Result = num2
End If
Return Result
End Function
End Module
OUTPUT
Program to find sum of two numbers using function
Module Program
Sub Main()
Console.WriteLine("Program to find sum of two
numbers using function")
Dim a, b As Integer
Console.WriteLine("Enter the value of a: ")
a = Console.ReadLine()
Console.WriteLine("Enter the value of b: ")
b = Console.ReadLine()
Dim sum As Integer = FindSum(a, b)
Console.WriteLine("Sum of two numbers is {0} ",
sum)
Console.WriteLine("Press any key to exit")
Console.ReadKey()
End Sub
Function FindSum(ByVal num1 As Integer, ByVal
num2 As Integer) As Integer
Dim Result As Integer
Result = num1 + num2
FindSum = Result
End Function
End Module
OUTPUT
Program to find factorial of n number using recursion
Imports System
Module Program
Function factorial(ByVal num As Integer)
Dim result As Integer
If num = 1 Then
Return 1
Else
result = factorial(num - 1) * num
Return result
End If
End Function
Sub main()
Console.WriteLine("Program to find factorial of n
number using recursion")
Dim n As Integer
Console.WriteLine("Enter the value of n: ")
n = Console.ReadLine()
Console.WriteLine("Factorial={0}", factorial(n))
Console.ReadKey()
End Sub
End Module
OUTPUT
Program to swap two numbers as passing argument by
Value
Imports System
Module Program
Sub Main(args As String())
Console.WriteLine("Program to swap two numbers
as passing argument by Value")
Dim a, b As Integer
Console.WriteLine("Enter the value of a and b")
a = Console.ReadLine()
b = Console.ReadLine()
Console.WriteLine("Before calling Swap
procedure")
Console.WriteLine("a is {0}", a)
Console.WriteLine("b is {0}", b)
Swap(a, b)
Console.WriteLine("After calling swap procedure")
Console.WriteLine("a is {0}", a)
Console.WriteLine("b is {0}", b)
Console.WriteLine("Press any key exit")
Console.ReadLine()
End Sub
Sub Swap(ByVal a As Byte, ByVal b As Byte)
Dim temp As Byte
temp = a
a=b
b = temp
Console.WriteLine("Inside Swap procedure")
Console.WriteLine("a is {0}", a)
Console.WriteLine("b is {0}", b)
End Sub
End Module
OUTPUT
Program to find factorial of a number using recursion
Imports System
Module Program
Function factorial(ByVal num As Integer)
Dim result As Integer
If num = 1 Then
Return 1
Else
result = factorial(num - 1) * num
Return result
End If
End Function
Sub main()
Console.WriteLine("Program to find factorial of n
number using recursion")
Dim n As Integer
Console.WriteLine("Enter the value of n: ")
n = Console.ReadLine()
Console.WriteLine("Factorial={0}", factorial(n))
Console.ReadKey()
End Sub
End Module
OUTPUT
OUTPUT
Imports System
Module Program
Public Class User
Public Name As String
Private Location As String
Public Sub New()
Console.WriteLine("Base Class Constructor")
End Sub
Public Sub GetUserInfo(ByVal loc As String)
Location = loc
Console.WriteLine("Name: {0}", Name)
Console.WriteLine("Location: {0}", Location)
End Sub
End Class
Imports System
Module Module1
Class User
Private location As String
Private name As String
Public Property Ulocation() As String Get Return location
End Get Set(ByVal value As String)
location = value
End Set
End Property
Public Property Uname() As String
Get
Return name
End Get
Set(ByVal value As String)
name = value
End Set
End Property
End Class
Sub Main()
Dim u As User = New User()
u.Uname = "Mohit"
u.Ulocation = "Rajouri"
Console.WriteLine("Program is to illustrate
Encapsulation")
Console.WriteLine("Name: " & u.Uname)
Console.WriteLine("Location: " & u.Ulocation)
Console.WriteLine("Press Enter Key to Exit..")
Console.ReadLine()
End Sub
End Module
OUTPUT
Program to Demonstrate simple windows form
End Sub
End Sub
OUTPUT
Program to create registration form with ADO.Net
Imports System.Data.SqlClient
End If
con.Close()
End Sub
Private Sub cancel_register_Click(sender As Object, e
As EventArgs) Handles cancel_register.Click
Me.Hide()
Form1.Show()
End Sub
End Class
OUTPUT
Program to create login form with ADO.Net
Imports System.Data.SqlClient
Public Class Login
Private Sub Button2_Click(sender As Object, e As
EventArgs) Handles Button2.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C
:\Users\mohit\OneDrive\Desktop\form\RegistrationFo
rm\RegistrationForm\registration.mdf;Integrated
Security=True"
con.Open()
Dim stmt As String = "Select * From users WHERE
email='" & email.Text & "' AND password = '" &
password.Text & "'"
cmd = New SqlCommand(stmt, con)
Dim reader As SqlDataReader =
cmd.ExecuteReader
If reader.Read Then
MessageBox.Show("you have logged in
Successfully")
Me.Hide()
Else
MessageBox.Show("Invalid username or
password")
email.Clear()
password.Clear()
End If
con.Close()
End Sub