Pages

Search This Blog

Well these are all with console programming.
If you follow these programs from no.1 to no.64 you wont have any trouble learning the console part.
From next week I will start uploading windows part.
As before the programs will start from very basic to moderate level.
If you have any queries/comments/programs-you-like-to-share please do...
I will do my best to solve.
Thank you.

Simple Interface Example


Module IntefaceExample
 
    Sub Main()
        Dim obj As New Class2
        obj.add()
        obj.pro()
        Console.ReadLine()
    End Sub
 
End Module
 
Interface in1
    Sub add()
End Interface
 
Interface in2
    Sub pro()
End Interface
 
Interface in3
    Inherits in1, in2
End Interface
 
 
Public Class Class2 : Implements in3
 
    Public Sub add() Implements in1.add
        Console.WriteLine("Add Function...")
    End Sub
 
    Public Sub pro() Implements in2.pro
        Console.WriteLine("Product Function...")
    End Sub
End Class

Exception Handling Example


Module ExecptionHandlingExample
 
    Sub Main()
        Dim a, b, c As Integer
        Console.Write("Enter a and b :")
        a = CInt(Console.ReadLine)
        b = CInt(Console.ReadLine)
        Console.WriteLine("a = " + a.ToString())
        Console.WriteLine("b = " + b.ToString())
        Console.WriteLine()
        Try
            c = a \ b
            Console.WriteLine("c = " + c.ToString())
        Catch ex As Exception
            Console.WriteLine("Exception occured: " + ex.Message())
        End Try
        Console.ReadLine()
    End Sub
 
End Module


Execute Windows Programs from VB.net




Module FunProgram

    Sub Main()

        'executes/open any program which is given under quotes
        'you can run each process or can run a list of processess
        System.Diagnostics.Process.Start("notepad.exe")
        System.Diagnostics.Process.Start("www.kodderkiddie.blogspot.in")
        
    End Sub

End Module


Abstract Class Example


Public MustInherit Class Class1
    Public n As Integer
    Sub New()
        Console.WriteLine("Inside Abstract CLass1 Constructor...")
        Console.Write("Enter a number = ")
        n = CInt(Console.ReadLine)
    End Sub
    MustOverride Sub display()
End Class
 
 
Public Class Class2 : Inherits Class1
 
    Public Overrides Sub display()
        Console.WriteLine("n= " + n.ToString())
    End Sub
End Class
 
Module AbstractClassExample
    Sub Main()
        Dim obj As Class1
        Dim obj1 As New Class2
        obj = obj1
        obj.display()
        Console.ReadLine()
    End Sub
End Module


Output:
Inside Abstract CLass1 Constructor...
Enter a number = 2 
n= 2

Threading Example


Imports System.Threading

Module ThreadingDisplay

    Sub Main()
        Dim firstThread As New Thread(New ThreadStart(AddressOf Fun1))
        Dim secondThread As New Thread(New ThreadStart(AddressOf Fun2))
        firstThread.Start()
        secondThread.Start()
        firstThread.Join()
        secondThread.Join()
        Console.WriteLine("End of Main Thread...")
        Console.ReadLine()
    End Sub
    Sub fun1()

        Dim i As Integer
        For i = 1 To 10
            Console.WriteLine("From 1st Thread i= " + i.ToString())
            Thread.Sleep(1000)
        Next
    End Sub
    Sub fun2()

        Dim j As Integer
        For j = 20 To 11 Step -1
            Console.WriteLine("From 2nd Thread j= " + j.ToString())
            Thread.Sleep(1000)
        Next
    End Sub
End Module

Sum by Function Overloading


Module SumByFuncOverloading

    Sub Main()
        Dim a, b, s1, s2 As Integer
        Console.Write("Enter the value of a: ")
        a = CInt(Console.ReadLine())
        Console.Write("Enter the value of b: ")
        b = CInt(Console.ReadLine())
        Console.WriteLine()
        Console.WriteLine("Display")
        Console.WriteLine("a= " + a.ToString())
        Console.WriteLine("b= " + b.ToString())
        'function overloading
        s1 = add(a)
        s2 = add(a, b)
        Console.WriteLine()
        Console.WriteLine("Sum1= " + s1.ToString())
        Console.WriteLine("Sum2= " + s2.ToString())
        Console.ReadLine()
    End Sub
    Function add(ByVal m As Integer) As Integer
        'adding 100 to m
        m += 100
        Return m
    End Function
    Function add(ByVal p As Integer, ByVal q As Integer) As Integer
        Return p + q
    End Function
End Module

Sum Using Derived Class


Public Class Class1
    Protected a As Integer
    Sub New()
        Console.WriteLine("Inside Class1 Constructor...")
        Console.Write("Enter Number: ")
        a = CInt(Console.ReadLine())
    End Sub
    Sub display()
        Console.WriteLine("a=" + a.ToString())
    End Sub
End Class


Public Class Class2 : Inherits Class1
    Protected b As Integer
    Sub New()
        Console.WriteLine()
        Console.WriteLine("Inside Class2 Constructor...")
        Console.Write("Enter Number: ")
        b = CInt(Console.ReadLine())
    End Sub
    Sub disp()
        Console.WriteLine("b=" + b.ToString())
    End Sub
    Sub add()
        Console.Write("Sum = " + (a + b).ToString())
    End Sub
End Class


Module SumUsingDerivedClass
    Sub Main()
        Dim obj As New Class2
        Console.WriteLine()
        obj.display()
        obj.disp()
        Console.WriteLine()
        obj.add()
        Console.ReadLine()
    End Sub
End Module