Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. No accessible 'Main' method

No accessible 'Main' method

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestionworkspace
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KreativeKai
    wrote on last edited by
    #1

    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

    M B 2 Replies Last reply
    0
    • K KreativeKai

      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

      M Offline
      M Offline
      Mike Mestemaker
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • M 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

        K Offline
        K Offline
        KreativeKai
        wrote on last edited by
        #3

        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

        W 1 Reply Last reply
        0
        • K KreativeKai

          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

          W Offline
          W Offline
          William Bartholomew
          wrote on last edited by
          #4

          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

          K 1 Reply Last reply
          0
          • W William Bartholomew

            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

            K Offline
            K Offline
            KreativeKai
            wrote on last edited by
            #5

            I tested your suggestion and it also worked very well. Thanks!!:-O

            1 Reply Last reply
            0
            • K KreativeKai

              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

              B Offline
              B Offline
              bensoncd
              wrote on last edited by
              #6

              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

              K 1 Reply Last reply
              0
              • B bensoncd

                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

                K Offline
                K Offline
                KreativeKai
                wrote on last edited by
                #7

                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

                B 1 Reply Last reply
                0
                • K KreativeKai

                  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

                  B Offline
                  B Offline
                  bensoncd
                  wrote on last edited by
                  #8

                  A quick one, thanks mate for your contribution. Will be trying it now. Will get back to you soon. Well, I thought of beginning programming using VB.NET because there seems to be a lot of useful knowledge to be gained from it. Regards, Ben

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups