PUser PUser - 1 year ago 113
Vb.net Question

Error. .. Main not accessible by program

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)
Console.WriteLine("parameter failure")
End If
End Sub

End Module

Answer Source

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()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download