-4

I've got a module in VB like this

Module Module1

    Sub Main()
        /* some piece of code here */
    End Sub

End Module

And I want to execute its Main from a project in C# because both the languages comes under .net so is there a way to achieve this?

piedpiper
  • 520
  • 5
  • 18
Josemafuen
  • 682
  • 2
  • 16
  • 41
  • 6
    So, what have you tried and where's the problem? – UnholySheep Oct 23 '17 at 15:00
  • Possible duplicate of [How to call a VBScript file in a C# application?](https://stackoverflow.com/questions/200422/how-to-call-a-vbscript-file-in-a-c-sharp-application) – xGeo Oct 23 '17 at 15:00
  • 1
    VB what? `VB6`, `VB.NET`, `VBA` ... something else? If its not managed did you make it COM visible? Have you tried *anything* at all? – Igor Oct 23 '17 at 15:02

2 Answers2

0

Add reference

Build it as a DLL, put Public in front of some thing slike this

Public Module Module1
 ... Public sub Main

and add the dll as a reference to the c# project. DONE.

But the VB app is an EXE and this is the startup sub!

You can't use it like that.

I guess you can!

see amy's comment. I swear I tried it at one point ... and failed... sorry about that.

Community
  • 1
  • 1
FastAl
  • 6,194
  • 2
  • 36
  • 60
  • 1
    You can add a reference to an executable, and you can call `main`. It's just a function. –  Oct 23 '17 at 15:06
0

a VB.Net Module is a C# Static Class. so, if you reference the VB.Net Project or Vb.Net Compiled Assembly, you can call Main sub routine in this way:

Module1.Main();

but to do that, Module1 and Main must be marked as public:

Public Module Module1

    Public Sub Main()
        /* ..... */
    End Sub

End Module
Giancarlo Melis
  • 697
  • 4
  • 17