0

I wrote a module and into which a Public Sub Main method. But, when I run the program. It gives " No accessible 'Main' method with an appropriate signature was found in 'abc'."

Could you please suggest possible solutions to the error.

 Public Sub Main(ByVal cmdArgs As String)
    Dim returnValue As Integer
    If cmdArgs.Length > 0 Then
        returnValue = Import_Start(cmdArgs, "f9880")
        Console.WriteLine("Import end with an error " & returnValue)
    Else
        Console.WriteLine("parameter failure")
    End If
End Sub

End Module

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • can you add the code in which you are calling your sub `main`? – Aethan May 04 '16 at 01:01
  • You would never call that Sub Main. That provides an alternate way to start a Winforms app. Set it as the startup object in project properties, or change that name if that is not what you are trying to do. – Ňɏssa Pøngjǣrdenlarp May 04 '16 at 01:07
  • @Plutonix, can you explain further? Does it have something to do with the sub name being _Main_? I'm puzzled. Kindly enlighten me. – Aethan May 04 '16 at 01:09
  • @CrushSundae [This answer explains it](http://stackoverflow.com/a/25554057/1070452) It is not clear if that is what the OP is trying to do. The problem may be that the signature is wrong: `cmdArgs As String()` it passes the (optional) args as an array. See also http://stackoverflow.com/a/21413464 – Ňɏssa Pøngjǣrdenlarp May 04 '16 at 01:14
  • @Plutonix, correct me if I'm wrong, so it doesn't have something to do with the name of the sub? It still depends on what you set as your application's starting point? Right? – Aethan May 04 '16 at 01:18
  • Yes, it must be `Public Sub Main` in a module or `Public Shared Sub Main()` in a form. There can only be one main in the project and optionally you can get the command line args as a param to it `args As String()` which is the problem here. @CrushSundae – Ňɏssa Pøngjǣrdenlarp May 04 '16 at 01:24
  • @Plutonix, thanks for the additional knowledge! – Aethan May 04 '16 at 01:35

1 Answers1

0

If you want to start your app from a Sub Main, the correct signature is:

Public Sub Main(args As String())
' or
Public Sub Main()

The command line args will be passed as a string array. Yours just declares it as String resulting in the compiler error. You also need to set the StartUp object to Sub Main in Project Properties, but that already seems to have been done.

If you do not want/need to use a module you can add it to a form (it is not clear if this is even a WinForms app) using:

Public Shared Sub Main(args As String())
' or
Public Shared Sub Main()
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • Thanks Plutonix for your help. Although after couple of documents, i figured it out. But, thanks for the explanation. –  May 04 '16 at 05:24