ARTICLE

How to use VB Component in C#?

Posted by Vivek Gupta Articles | Visual Basic 2010 May 28, 2004
I have tried to show by example how to use VB components in C#. As I am beginner for .NET technologies, so always try to use easiest examples so that it is easy to get for beginners.
 
Reader Level:

I have tried to show by example how to use VB components in C#. As I am beginner for .NET technologies, so always try to use easiest examples so that it is easy to get for beginners.

Hello World program in VB (hellovb.vb).

Imports
System
Namespace
hellovb
Public Class
HelloString
Public Function GetString() As
String
Console.WriteLine("Hello World in Visual Basic Program")
End
Function
End
Class
End
Namespace

Compile it using vbc  /t:library hellovb.vb.

This command will generate hellovb.dll.

Hello World program in C# (hellocs.cs).

using
System;
namespace
hellocs
{
public class
displayA
{
public void
Displayhello()
{
Console.WriteLine("Hello in C# Program");
}
}
}

Compile it using csc  /t:library hellocs.cs.

This command will generate hellocs.dll.

Main program(in c#) in which we will use these libraries. 

Main Program in C# (maincs.cs).

using
System;
using
hellocs;
using
hellovb;
class
maincs
{
public static void
Main()
{
hellovb.HelloString vb =
new hellovb.HelloString();
// namespace.classname of
hellovb.vb
vb.GetString();
//Calling vb function
hellocs.displayA cs = new hellocs.displayA();
// namespace.classname of hellocs.cs
cs.Displayhello();
//Calling vb function
}
}

Compile it using command csc  maincs.cs /r:hellocs.dll;hellovb.dll.

Output will be.

Hello World in Visual Basic Program.

Hello in C# Program.

Login to add your contents and source code to this article
share this article :
post comment
 

I would like to use vb component which has a event in vc#.

Actually, I would like to use vb component's event in vc#.

Is it possible?

pls give me an idea.

Many thanks,

Posted by Jae hong Lee Jul 16, 2009
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor