No accessible 'Main' method
-
Hi, I'm trying to setup my VB executable to pull in a parameter when the executable is called. For example: MessageOperator.exe /B Here is what I've setup so far: Public Class MessageOperator Public Shared Sub Main(Optional ByVal strOption As String = "A") if strOption = "A" then ... else ... end if At compile time I'm getting the following error: No accessible 'Main' method with an appropriate signature was found in 'MessageTheOperator'. I'm either doing something stupid or heading in the right direction, but missing one small item. Anyone have a suggestion? Kevin
-
Hi, I'm trying to setup my VB executable to pull in a parameter when the executable is called. For example: MessageOperator.exe /B Here is what I've setup so far: Public Class MessageOperator Public Shared Sub Main(Optional ByVal strOption As String = "A") if strOption = "A" then ... else ... end if At compile time I'm getting the following error: No accessible 'Main' method with an appropriate signature was found in 'MessageTheOperator'. I'm either doing something stupid or heading in the right direction, but missing one small item. Anyone have a suggestion? Kevin
In VB, the command line parameters are read from a function (like "Command"). They are not passed into the Main as parameters. Remove the parameter from Sub Main and re-code it to read the parameter from the Command function and you should be all set. Mike Mestemaker
-
In VB, the command line parameters are read from a function (like "Command"). They are not passed into the Main as parameters. Remove the parameter from Sub Main and re-code it to read the parameter from the Command function and you should be all set. Mike Mestemaker
Thanks, I did the following and it worked like a charm: Dim strMode As String = Microsoft.VisualBasic.Command() If strMode = "Report" Then MsgBox("Print Report") Else MsgBox("Display Form") End If The program is executed: program.exe Report Thanks again!! Kevin
-
Thanks, I did the following and it worked like a charm: Dim strMode As String = Microsoft.VisualBasic.Command() If strMode = "Report" Then MsgBox("Print Report") Else MsgBox("Display Form") End If The program is executed: program.exe Report Thanks again!! Kevin
The problem was that you didn't have the signature of your Main correct, rather than using the Microsoft.VisualBasic compatibility namespace you could do the following: Public Shared Sub Main(ByVal args() As String) Dim strMode As String If args.Length > 0 Then strMode = args(0) End If If strMode = "Report" Then MsgBox("Print Report") Else MsgBox("Display Form") End If End Sub
-
The problem was that you didn't have the signature of your Main correct, rather than using the Microsoft.VisualBasic compatibility namespace you could do the following: Public Shared Sub Main(ByVal args() As String) Dim strMode As String If args.Length > 0 Then strMode = args(0) End If If strMode = "Report" Then MsgBox("Print Report") Else MsgBox("Display Form") End If End Sub
I tested your suggestion and it also worked very well. Thanks!!:-O
-
Hi, I'm trying to setup my VB executable to pull in a parameter when the executable is called. For example: MessageOperator.exe /B Here is what I've setup so far: Public Class MessageOperator Public Shared Sub Main(Optional ByVal strOption As String = "A") if strOption = "A" then ... else ... end if At compile time I'm getting the following error: No accessible 'Main' method with an appropriate signature was found in 'MessageTheOperator'. I'm either doing something stupid or heading in the right direction, but missing one small item. Anyone have a suggestion? Kevin
Hi Kevin, Ben here, I guess you will be proud to know that you can at least help me on this 'Sub Main' issue. I have just started doing my first project in VB.NET. When I try running my project i get an error code indicating that 'Sub Main ' is missing . Could you please explain to me what this 'Sub Main' is all about, and how I can include it in my project. Regards, Ben
-
Hi Kevin, Ben here, I guess you will be proud to know that you can at least help me on this 'Sub Main' issue. I have just started doing my first project in VB.NET. When I try running my project i get an error code indicating that 'Sub Main ' is missing . Could you please explain to me what this 'Sub Main' is all about, and how I can include it in my project. Regards, Ben
With VB you can designate where you want your application to start. For example you might want it to start with a form, a class or a module. If you start with a class or module VB is looking for Sub Main by default. When you look at your project in Solution Explorer you'll see a list like the one shown below: Solution test (1 project) test References AssemblyInfo.vb Class1.vb Form1.vb Right click on the second line (which is test above) and left click on properties. You'll see a drop-down menu called "Startup object". Pull that menu down and select what sub routine or form you would like your application to start with. Instructors of VB intro courses always seem to code in the form. This is fine for small financial calculator projects that they have you create while training, but when you start coding larger projects and have multiple forms and sub procedures you can start the application with a "Sub Main" in a class or a module to control all your forms. Hope this helps. I've been coding in COBOL for 14 years and just recently started working with VB .NET because the company is going from a mainframe environment to a PC environment. I'm only on my 4th or 5th project and definitely consider myself a beginner. Hang in there... With .NET there is so much to learn that information overload can become a problem. Eventually the concepts will fall into place for you. Kevin :-O
-
With VB you can designate where you want your application to start. For example you might want it to start with a form, a class or a module. If you start with a class or module VB is looking for Sub Main by default. When you look at your project in Solution Explorer you'll see a list like the one shown below: Solution test (1 project) test References AssemblyInfo.vb Class1.vb Form1.vb Right click on the second line (which is test above) and left click on properties. You'll see a drop-down menu called "Startup object". Pull that menu down and select what sub routine or form you would like your application to start with. Instructors of VB intro courses always seem to code in the form. This is fine for small financial calculator projects that they have you create while training, but when you start coding larger projects and have multiple forms and sub procedures you can start the application with a "Sub Main" in a class or a module to control all your forms. Hope this helps. I've been coding in COBOL for 14 years and just recently started working with VB .NET because the company is going from a mainframe environment to a PC environment. I'm only on my 4th or 5th project and definitely consider myself a beginner. Hang in there... With .NET there is so much to learn that information overload can become a problem. Eventually the concepts will fall into place for you. Kevin :-O