All Programs in Vbnet
All Programs in Vbnet
Net
'---Program : 1 {print the initial statements}
Imports System
'Program to print the Message , this is a comment
Module Module1
Sub Main()
Console.WriteLine("Program : 1 To say Hello India")
Console.WriteLine("Hello India")
Console.ReadKey() 'Like the getch() of the C
End Sub
End Module
'---Program 2
'Class Object Program , to find the area of the rectangle
Imports System
Module Module2
Sub Main()
Console.WriteLine("Program : 2 Use oops to find the area of the rectangle")
Dim x As New Rectangle()
x.Input()
x.Process()
x.Display()
Console.ReadKey()
End Sub
End Module
Public Class Rectangle
Dim Length, Width, Result As Integer
End Class
Imports System
Module Module3
'program : average of the 5 numbers
Sub Main()
Console.WriteLine("Program : 3 find the average of 5 numbers")
Dim x As New Avg()
x.Input()
x.Process()
x.Display()
Console.ReadKey()
End Sub
End Module
End Class
'--Program 4
'To Acept the values from the user and display its sum by the module method
Imports System
Module Module4
Sub Main()
Console.WriteLine("Program : 4 user input, display its sum by the module method")
Imports System
Module Module5
Sub Main()
Console.WriteLine("Program : 5 Do Add using Class and object")
Dim x As New DoAdd()
x.Input()
x.Process()
x.Display()
Console.ReadKey()
End Sub
End Module
End Class
Imports System
Module Module6
Sub Main()
Console.WriteLine("Program : 6 Use If and End If To compare 2 user Input")
Dim x, y As Integer
x = Console.ReadLine()
y = Console.ReadLine()
'All Blocks of If are seperately closed with end if
If x > y Then
Console.WriteLine("Value x is bigger than y")
End If
If x < y Then
Console.WriteLine("Value y is Bigger than y")
End If
If x = y Then
Console.WriteLine("Both the Values are Equal")
End If
Console.ReadKey()
End Sub
End Module
If x > y Then
Console.WriteLine("Value x is bigger than y")
Else
Console.WriteLine("Value y is Bigger than x")
End If
Console.ReadKey()
End Sub
End Module
'Program8
'To Accept 4 Values and then Compare to find the bigger one
Imports System
Module Module8
Sub Main()
Console.WriteLine("Program : 8 Accept 4 Values ,Compare to find the bigger one")
Dim a1, a2, a3, a4 As Integer
a1 = Console.ReadLine()
a2 = Console.ReadLine()
a3 = Console.ReadLine()
a4 = Console.ReadLine()
Imports System
Module Module9
Sub Main()
Console.WriteLine("Program : 9 Use If To make a Electric Bill Calculator")
Dim amt, unit As Integer
unit = Console.ReadLine()
If unit > 1 And unit <= 150 Then
amt = unit * 6.4
Else
amt = unit * 15.5
End If
Console.ReadKey()
End Sub
End Module
Imports System
Module Module10
Sub Main()
Console.WriteLine("Program : 10 WAP ,User input to check even or odd")
If val = 0 Then
Console.WriteLine("The No. is 0")
Imports System
Module Module11
Sub Main()
Console.WriteLine("Program : 11 Make Days Selecter Using the Switch Case")
Console.WriteLine("Hey , USer , Give input from the no. btw 1 to 7 for days")
Dim inpp As Integer = Console.ReadLine()
Case 1
Console.WriteLine("Monday")
Case 2
Console.WriteLine("Tuesday")
Case 3
Console.WriteLine("Wednesday")
Case 4
Console.WriteLine("Thursday")
Case 5
Console.WriteLine("Friday")
Case 6
Console.WriteLine("Saturday")
Case 7
Console.WriteLine("Sunday")
Case Else
Console.WriteLine("Invalid Input")
End Select
Console.ReadKey()
End Sub
End Module
Imports System
Module Module12
Sub Main()
Console.WriteLine("Program : 12 User Give Any Inst . To Add (Select Case)")
Dim inpp, st1, st2 As String
Dim Val1, Val2 As Integer
Console.WriteLine("Give a /A/Add/Addition/+ to start Addition")
inpp = Console.ReadLine()
Console.WriteLine("Give Value 1")
st1 = Console.ReadLine()
Integer.TryParse(st1, Val1)
Console.WriteLine("Give Value 2")
st2 = Console.ReadLine()
Integer.TryParse(st2, Val2)
Case "+"
Case "a"
Case "A"
Case "Add"
Case "Addition"
Console.WriteLine("The Sum is ={0}", (Val1 + Val2))
Console.ReadKey()
Case Else
Console.WriteLine("Program fail!")
End Select
Console.ReadKey()
End Sub
End Module
Sub Main()
Console.WriteLine("Program : 13 store and Display 10 values of the array")
Dim i, x(10) As Integer
For i = 0 To 9
Console.WriteLine("Give value{0}", i)
x(i) = Console.ReadLine()
Next i
For i = 0 To 9
Console.WriteLine(x(i))
Next i
Console.ReadKey()
End Sub
End Module
Module Module18
' for the Array Functions
Dim StudentRoll(5) As Integer
Sub Main()
Console.WriteLine("Other functions for the Arrays")
Console.WriteLine("the Upper Bound and Lower Bound methods")
For i As Integer = 0 To 4
StudentRoll(i) = 9
Console.Write(StudentRoll(i))
Next
Console.Write("Now the Size is redimensioned to 8 ")
ReDim StudentRoll(8)
For i As Integer = 0 To 7
StudentRoll(i) = 10
Console.Write(StudentRoll(i))
Next
Console.WriteLine()
Console.WriteLine("The upper Bound is by the UBound(StudentRoll)= " & UBound(StudentRoll))
Console.WriteLine()
Console.WriteLine("The lower Bound is by the LBound(StudentRoll)= " & LBound(StudentRoll))
Console.WriteLine()
Console.WriteLine("The size is by the UBound(StudentRoll)-1= " & (UBound(StudentRoll) - 1))
Console.WriteLine(" Now Redimensioning with Preserving , size inc . to 10 ")
ReDim Preserve StudentRoll(10)
StudentRoll(8) = 22
StudentRoll(9) = 33
Console.WriteLine(" Now Printing All of them")
For i As Integer = 0 To 9
Console.WriteLine(StudentRoll(i))
Next
Console.ReadKey()
End Sub
End Module
Module Module19
Sub Main()
'Other methods for the Arrays:
Console.WriteLine("The Elements of the array is in the seq:")
Dim sampleArray() As Integer = {1, 2, 3, 4, 5}
For i As Integer = 0 To UBound(sampleArray)
Console.WriteLine("the Array is Like :" & sampleArray(i))
Next
Module Module20
Sub Main()
Console.WriteLine("To clear the array from the start to end index (user Specified)")
Dim Arr(19) As Integer
For i As Integer = 0 To 4
Arr(i) = 0
'Initialising 1st 5 places with 0
Next
For i As Integer = 5 To 14
Arr(i) = 5
'Initialising middle 10 places with 5
Next
For i As Integer = 15 To 19
Arr(i) = 7
'Initialising last 5 places with 7
Next
Next
Console.WriteLine("1st 5 places : 0 , middle places : 5 , end places : 7")
' to clear the end 7
Array.Clear(Arr, 15, 5)
'3rd value 5 is the length , means 5 boxes ahead the 15 index
Console.WriteLine("after clear the array the result is :")
Console.WriteLine()
For i As Integer = 0 To UBound(Arr)
Console.Write(Arr(i) & ",")
Next
Console.ReadKey()
End Sub
End Module
Console.WriteLine()
Console.WriteLine("Using the Exit For to get out of the loop when i =5")
'Exit For-------
Dim i1 As Integer
For i1 = 0 To 10 Step 1
If i1 = 5 Then
Exit For
End If
Console.WriteLine(i1)
Next
Console.WriteLine()
Console.WriteLine("Using the return statement")
'Continue-------
Dim i2 As Integer
For i2 = 0 To 10 Step 1
If i2 = 5 Then
Dim receiveValue As Integer = i2
Console.WriteLine("Value returned ={0}", receiveValue)
End If
Next
Console.ReadKey()
End Sub
End Module
Module Module14
Sub Main()
Dim times As DateTime = DateTime.Now()
Console.WriteLine("'1 month day , year")
Console.WriteLine("{0:MMMM dd , yyyy}", times)
Console.WriteLine("'2 month/day/year ")
Console.WriteLine("{0:M /d/yyyy}", times)
Console.WriteLine("'3 to abbreiviete the name of the week")
Console.WriteLine("{0:ddd}", times)
Console.WriteLine("'4 to show the week name as full")
Console.WriteLine("{0:dddd}", times)
Console.WriteLine("'5 to use the 12 hr clock")
Console.WriteLine("{0:hh}", times)
Console.WriteLine("'6 to use the 24 he clock")
Console.WriteLine("{0:HH}", times)
Console.WriteLine("'7 to use the Am/Pm")
Console.WriteLine("{0:tt}", times)
Console.WriteLine("'8 to show the time in the format:")
Console.WriteLine("{0:hh:mm:ss:fff}", times)
Console.ReadKey()
End Sub
End Module
Namespace books
Public Class Myname_Author
Public Sub PrintMyName(ByVal str1 As String)
Console.WriteLine("Hello your name is " & str1)
End Sub
End Class
End Namespace
' now see its use in the program'
Imports System
Imports VbNet_Programming_Project.books
Module Module15
Sub Main()
Dim obj1 As New Myname_Author
obj1.PrintMyName("Aayush Sahay")
Console.ReadKey()
End Sub
End Module
Sub Main()
Dim s As New Simple()
Dim del As MyDelegate = AddressOf s.SayHello
del()
Console.Read()
End Sub
End Module
Module Module17
Public Delegate Sub myDel1()
Public Delegate Sub myDel2(ByVal A As Integer)
End Module
Imports System
Module EntryPoint
Sub Main()
Module17.Main()
'Run Module 5
Module5.Main()
End Sub
End Module
Imports System.Windows.Forms
End Property
End Property
End Property
End Property
End Property
End Property
End Class
'summary: this is a class file having the getter and the setter methods to runtime initialise the class vairables
End Sub
End Class
Public Class A
Public Overridable Sub disp(ByVal a As Integer, ByVal b As Integer)
MsgBox("[Class A Method]Display Sum :" & a + b)
End Sub ' for the ovverriding we use the above keyword
Public Class B
Inherits A ' Now we can also implement the overrding and overloading methods
'in the base class b
' From the Run the methods button we will run all the methods
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'here the show is overloaded , and disp is overriden
'Make the object of the sub class
'We see that the overriding function disp , will be 1st run by the base class
'then by the help of MyBase , the Super Class disp function will run
End Sub
End Class
Public Class B
Inherits A
End Class
Imports VbNet_Programming_Project
Interface I
Sub display()
Function output(ByVal User_input As String) As String
End Interface
End Class