MSDN Library

Figure 1

Figure 1 The CLR Replaces COM, MTS, and COM+ Runtimes

Windows NT 4.0
Windows 2000
.NET Platform
Your Code
Unmanaged Visual Basic 6.0 code
Unmanaged Visual Basic 6.0 code
Managed Visual Basic .NET code
Language-specific Integration Layer
Visual Basic Runtime MSVBVM60.DLL
Visual Basic Runtime MSVBVM60.DLL
CLR Runtime MSCOREE.DLL MSCORLIB.DLL
Context Concurrency Transactions
MTS Runtime MTXEX.DLL
COM+ Runtime OLE32.DLL OLEAUT32.DLL
CLR Runtime MSCOREE.DLL MSCORLIB.DLL
Class Loading and Remoting
COM Runtime OLE32.DLL OLEAUT32.DLL
COM+ Runtime OLE32.DLL OLEAUT32.DLL
CLR Runtime MSCOREE.DLL MSCORLIB.DLL
Figure 2 Console-based App Using Visual Basic .NET
' in the source file Hello.vb
Module MyApp
  Sub Main()
    Dim obj As Class1 = New Class1
    System.Console.WriteLine(obj.Method1)
  End Sub
End Module

Class Class1
  Function Method1()As String
    Return "Hello Visual Basic .NET"
  End Function
End Class
Figure 3 Managed Types
Enum Enum1
  Value1
  Value2
End Enum

Structure Structure1
  Public Field1 As Integer
  Public Field2 As Long
End Structure

Interface Interface1
  Sub Method1()
  Sub Method2()
End Interface

Class Class1
      Implements Interface1
  Public Field1 As Integer
  Private Field2 As Long
  Sub Method1() Implements Interface1.Method1
    ' implementation
  End Sub
  Sub Method2() Implements Interface1.Method2
    ' implementation
  End Sub
  Shared Sub Method3()
    ' implementation
  End Sub
End Class
Figure 4 Delegate Example
Delegate Sub Delegate1(ByVal s As String)

Module MyApp

  Sub Sub1(ByVal s As String)
      System.Console.WriteLine("From Sub1: " & s)
  End Sub

  Sub Sub2(ByVal s As String)
      System.Console.WriteLine("From Sub2: " & s)
  End Sub

  Sub Main  
      Dim MyFunctionPointer As Delegate1
      ' longhand syntax for creating and using a delegate
      MyFunctionPointer = New Delegate1(AddressOf Sub1)
      MyFunctionPointer.Invoke("Test message 1")
      ' shorthand syntax for creating and using a delegate
      MyFunctionPointer = AddressOf Sub2
      MyFunctionPointer("Test message 2")          
  End Sub

End Module
Figure 5 A Visual Basic .NET Class
Public Class EventClass1
  Public Event OnEvent1()
  Public Sub Method1()
    RaiseEvent OnEvent1()
  End Sub
End Class

Class ListenerClass1
  Private WithEvents Source As EventClass1
  Public Sub Register(ByVal s As EventClass1)
    Source = s
  End Sub
  Public Sub Unregister()
    Source = Nothing
  End Sub
  Private Sub TedsHandler() Handles Source.OnEvent1
    System.Console.WriteLine("Listener 1 handler executing")
  End Sub
End Class

Class ListenerClass2
  Private WithEvents Source As EventClass1
  Public Sub Register(ByVal s As EventClass1)
    Source = s
  End Sub
  Public Sub Unregister()
    source = Nothing
  End Sub
  Private Sub FredsHandler() Handles Source.OnEvent1
    System.Console.WriteLine("Listener 2 handler executing")
  End Sub
End Class

Module MyApp
  Public Sub Main()
    ' create event source object
    Dim ec As EventClass1 = New EventClass1
    ' create and sink up listener 1 object
    Dim listener1 As ListenerClass1 = New ListenerClass1
    listener1.Register(ec)
    ' create and sink up listener 2 object
    Dim listener2 As ListenerClass2 = New ListenerClass2
    listener2.Register(ec)
    ' call method which triggers events
    ec.Method1()
  End Sub
End Module
Show:
© 2016 Microsoft