Saturday 7 June 2014

program 23: interface

program to demonstrate concept of interface.

-----------------------------------------code---------------------------------------------------------


Imports System.Console
Module Module1

    Sub Main()
        Dim obj1 As New one
        Dim obj2 As New two
        obj1.disp()
        obj1.multiply()
        obj2.disp()
        obj2.multiply()
        ReadKey()
    End Sub

End Module
Public Interface test
    Sub disp()
    Function multiply() As Double
End Interface
Public Class one
    Implements test
    Public i As Double = 12
    Public j As Double = 12.17
    Public Sub disp() Implements test.disp
        WriteLine("sum=" & i + j)
    End Sub

    Public Function multiply() As Double Implements test.multiply
        WriteLine("muliplication=" & i * j)
    End Function
End Class
Public Class two
    Implements test
    Public a As Double = 20
    Public b As Double = 32.17
    Public Sub disp() Implements test.disp
        WriteLine("Welcome to interface")
    End Sub

    Public Function multiply() As Double Implements test.multiply
        WriteLine("multiplication=" & a * b)
    End Function
End Class
-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 22: abstract class

 program to demonstrate concept of abstract and not inheritable class.

-----------------------------------------code---------------------------------------------------------
Imports System.Console
Module Module1

    Public MustInherit Class abstractclass
        Public MustOverride Function add() As Integer
        Public MustOverride Function mul() As Integer
    End Class
    Public Class abstractone
        Inherits abstractclass
        Dim i As Integer = 20
        Dim j As Integer = 30
        Public Overrides Function add() As Integer
            Return i + j
        End Function

        Public Overrides Function mul() As Integer
            Return i * j
        End Function
    End Class
    Sub Main()
        Dim a As New abstractone
        WriteLine("sum is:" & a.add())
        WriteLine("multiplication is:" & a.mul())
        ReadKey()
    End Sub

End Module
-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 21: base class construction

program to demonstrate concept of base class construction.

-----------------------------------------code---------------------------------------------------------
Imports System.Console
Module Module1

    Sub Main()
        Dim w As New window(10, 5)
        w.drawwindow()
        Dim lb As New listbox(20, 30, "hello..!!")
        lb.drawwindow()
        Console.ReadKey()
    End Sub

End Module
Public Class window
    Private top As Integer
    Private left As Integer
    Public Sub New(ByVal top As Integer, ByVal left As Integer)
        Me.top = top
        Me.left = left
    End Sub
    Public Sub drawwindow()
        WriteLine("Drawing window at {0},{1}", top, left)
    End Sub
End Class
Public Class listbox
    Inherits window
    Public Sub New(ByVal top As Integer, ByVal left As Integer, ByVal tcontent As String)
        MyBase.New(top, left)
        mlstboxcontent = tcontent
    End Sub

    Public Shadows Sub drawwindow()
        Console.WriteLine("..........")
        MyBase.drawwindow()
        Console.WriteLine("Writing string to the listbox:{0}", mlstboxcontent)
    End Sub
    Private mlstboxcontent As String
End Class
-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 20: inheritance

program to demonstrate concept of inheritance.
-----------------------------------------code---------------------------------------------------------
Module Module1
    Class A
        Public Sub Show()
            Console.WriteLine("Calling from A")
        End Sub
    End Class

    Class B
        Inherits A
        Public Shadows Sub Show()
            Console.WriteLine("Calling from B")
        End Sub
    End Class

    Class C
        Inherits B
        Public Shadows Sub Show()
            Console.WriteLine("Calling from C")
        End Sub
    End Class
    Public Sub Main()
        Dim x As New A
        x.Show()
        x.Show()
        x.Show()
        Dim y As New B
        y.Show()
        Dim p1 As New C
        p1.Show()
        Console.ReadKey()
    End Sub
End Module
-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 19: get & set method

program to change height and width of image using get () and set () property.
-----------------------------------------code---------------------------------------------------------
Public Class Class1
    Public hei, wid As Integer
    Public Property height() As Integer
        Get
            Return hei
        End Get
        Set(ByVal value As Integer)
            hei = value
        End Set
    End Property
    Public Property width() As Integer
        Get
            Return wid
        End Get
        Set(ByVal value As Integer)
            wid = value
        End Set
    End Property
End Class

Public Class Form1
    Dim b, c As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As New Class1
        a.height = Val(TextBox1.Text)
        a.width = Val(TextBox2.Text)
        b = a.height
        c = a.width
        PictureBox1.Height = b
        PictureBox1.Width = c
    End Sub
End Class
Sonata Ocean Analog Watch - For Men(Black)
-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 18: lowercase to uppercase

program to demonstrate concept of simple class to convert lowercase text to uppercase.

-----------------------------------------code---------------------------------------------------------
Public Class Form1

    Public Class convertpostcode
        Public Function doconvert(ByVal postcode As String) As String
            Dim convertpostcode As String
            convertpostcode = StrConv(postcode, VbStrConv.Uppercase)
            doconvert = convertpostcode
        End Function
    End Class
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim newcode As String
        Dim obj As New convertpostcode
        newcode = obj.doconvert(TextBox1.Text)
        TextBox2.Text = newcode
    End Sub

End Class
End Module
-----------------------------------------output----------------------------------------------------


umesh sohaliya
codestrew

program 17: exception handling (console)

program to demonstrate the concept of exception handling

-----------------------------------------code---------------------------------------------------------
Imports System
Module module1
    Sub main()
        Dim x As Integer = 0
        Dim div As Integer
        Try
            div = 100 / x
            Console.WriteLine("Exception not occured")

        Catch ex As DivideByZeroException
            Console.WriteLine("Exception occured")
       
        Finally
            Console.WriteLine("Finally blocked")

        End Try
        Console.WriteLine("Result is {0}", div)
        Console.ReadKey()
    End Sub
End Module
-----------------------------------------output----------------------------------------------------


  
umesh sohaliya
codestrew

program 16: Enumeration

program to demonstrate Enumeration concept using enum keyword.

-----------------------------------------code---------------------------------------------------------

Imports System
Public Class Form1
    Enum day
        sunday = 1
        monday = 2
        tuesday = 3
        wednesday = 4
        thursday = 5
        friday = 6
        saturday = 7
    End Enum
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case TextBox1.Text
            Case 1
                MsgBox("sunday is " & day.sunday & " day")
            Case 2
                MsgBox("monday is " & day.monday & " day")
            Case 3
                MsgBox("tuesday is " & day.tuesday & " day")
            Case 4
                MsgBox("wednesday is " & day.wednesday & " day")
            Case 5
                MsgBox("thursday is " & day.thursday & " day")
            Case 6
                MsgBox("friday is " & day.friday & " day")
            Case 7
                MsgBox("saturday is " & day.saturday & " day")
            Case Else
                MsgBox("invalid number", , "message")
                TextBox1.Text = ""
        End Select
        TextBox1.Text = ""
    End Sub
End Class
-----------------------------------------output----------------------------------------------------



umesh sohaliya
codestrew

umesh sohaliya
codestrew