How to rename sub main to function main

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rody Reulen

    How to rename sub main to function main

    I made an console application with Visual Basic .net. Visual Basic will
    automatically create the sub procedure main for you. I try to convert the
    main procedure to a function.

    During the compilation I will get an error message:

    No accessible 'Main' method with an appropriate signature was found in
    <application> .

    I took a look at the following settings in Visual Basic dotnet:

    Project, properties, common properties, general, start object

    Here it's possible to define you startup project, but when I modify this
    option, the startup object is automatically reset to Sub Main in stead of
    Function Main.

    Does someone know how to change this?

    Thank in advance.

    Kind regards,

    Rody




  • Herfried K. Wagner [MVP]

    #2
    Re: How to rename sub main to function main

    * "Rody Reulen" <rreulen@romace l.nl> scripsit:[color=blue]
    > I made an console application with Visual Basic .net. Visual Basic will
    > automatically create the sub procedure main for you. I try to convert the
    > main procedure to a function.
    >
    > During the compilation I will get an error message:
    >
    > No accessible 'Main' method with an appropriate signature was found in
    > <application> .
    >
    > I took a look at the following settings in Visual Basic dotnet:
    >
    > Project, properties, common properties, general, start object
    >
    > Here it's possible to define you startup project, but when I modify this
    > option, the startup object is automatically reset to Sub Main in stead of
    > Function Main.[/color]

    Post the code you are using.

    --
    Herfried K. Wagner [MVP]
    <http://www.mvps.org/dotnet>

    Comment

    • José Manuel Agüero

      #3
      Re: How to rename sub main to function main

      Hello, Rody:

      The Main() method must have public access. If it is inside a class, it must also be shared:

      \\\
      module MyTestModule
      public sub Main()
      end sub
      end module

      class MyTestClass
      public shared sub Main()
      end sub
      end class
      ///

      Regards.


      "Rody Reulen" <rreulen@romace l.nl> escribió en el mensaje news:402a18a8$0 $31149$e4fe514c @dreader14.news .xs4all.nl...
      | I made an console application with Visual Basic .net. Visual Basic will
      | automatically create the sub procedure main for you. I try to convert the
      | main procedure to a function.
      |
      | During the compilation I will get an error message:
      |
      | No accessible 'Main' method with an appropriate signature was found in
      | <application> .
      |
      | I took a look at the following settings in Visual Basic dotnet:
      |
      | Project, properties, common properties, general, start object
      |
      | Here it's possible to define you startup project, but when I modify this
      | option, the startup object is automatically reset to Sub Main in stead of
      | Function Main.
      |
      | Does someone know how to change this?
      |
      | Thank in advance.
      |
      | Kind regards,
      |
      | Rody

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: How to rename sub main to function main

        Rody,
        As Herfried stated, post your code.

        Main can be a function as long as it returns an Integer.

        Also you can either have an array of string as a parameter or no parameters.

        For details see:



        and



        Hope this helps
        Jay

        "Rody Reulen" <rreulen@romace l.nl> wrote in message
        news:402a18a8$0 $31149$e4fe514c @dreader14.news .xs4all.nl...[color=blue]
        > I made an console application with Visual Basic .net. Visual Basic will
        > automatically create the sub procedure main for you. I try to convert the
        > main procedure to a function.
        >
        > During the compilation I will get an error message:
        >
        > No accessible 'Main' method with an appropriate signature was found in
        > <application> .
        >
        > I took a look at the following settings in Visual Basic dotnet:
        >
        > Project, properties, common properties, general, start object
        >
        > Here it's possible to define you startup project, but when I modify this
        > option, the startup object is automatically reset to Sub Main in stead of
        > Function Main.
        >
        > Does someone know how to change this?
        >
        > Thank in advance.
        >
        > Kind regards,
        >
        > Rody
        >
        >
        >
        >[/color]


        Comment

        • Rody Reulen

          #5
          Re: How to rename sub main to function main

          The problem is solved now.

          The reason why it did work was because I did specify:

          Function Main()
          ' Do something

          Return <integer value>
          End Function

          in stead of

          Function Main() as Integer
          'Do something

          Return <integer value>
          End Function

          As you can see I did not explicitly specify the returnvalue type from the
          function.

          Thanks for you help.

          Kind regards,

          Rody



          "Rody Reulen" <rreulen@romace l.nl> wrote in message
          news:402a18a8$0 $31149$e4fe514c @dreader14.news .xs4all.nl...[color=blue]
          > I made an console application with Visual Basic .net. Visual Basic will
          > automatically create the sub procedure main for you. I try to convert the
          > main procedure to a function.
          >
          > During the compilation I will get an error message:
          >
          > No accessible 'Main' method with an appropriate signature was found in
          > <application> .
          >
          > I took a look at the following settings in Visual Basic dotnet:
          >
          > Project, properties, common properties, general, start object
          >
          > Here it's possible to define you startup project, but when I modify this
          > option, the startup object is automatically reset to Sub Main in stead of
          > Function Main.
          >
          > Does someone know how to change this?
          >
          > Thank in advance.
          >
          > Kind regards,
          >
          > Rody
          >
          >
          >
          >[/color]


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: How to rename sub main to function main

            * "Rody Reulen" <rreulen@romace l.nl> scripsit:[color=blue]
            > The reason why it did work was because I did specify:
            >
            > Function Main()
            > ' Do something
            >
            > Return <integer value>
            > End Function
            >
            > in stead of
            >
            > Function Main() as Integer
            > 'Do something
            >
            > Return <integer value>
            > End Function
            >
            > As you can see I did not explicitly specify the returnvalue type from the
            > function.[/color]

            Always do that! I would specify an access modifier explicitly too.

            --
            Herfried K. Wagner [MVP]
            <http://www.mvps.org/dotnet>

            Comment

            • Phill.  W

              #7
              Re: How to rename sub main to function main

              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
              news:OVkfHnW8DH A.1548@tk2msftn gp13.phx.gbl...[color=blue]
              > * "Rody Reulen" <rreulen@romace l.nl> scripsit:[/color]
              .. . .[color=blue][color=green]
              > > Function Main() as Integer[/color][/color]
              .. . .[color=blue][color=green]
              > > Return <integer value>
              > > End Function[/color][/color]
              .. . .[color=blue]
              > I would specify an access modifier explicitly too.[/color]

              Herfried,

              Having never used an access modifier in this situation myself,
              which would you recommend and why?

              Regards,
              Phill W.


              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: How to rename sub main to function main

                * "Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> scripsit:[color=blue]
                > . . .[color=green][color=darkred]
                >>> Function Main() as Integer[/color][/color]
                > . . .[color=green][color=darkred]
                >>> Return <integer value>
                >>> End Function[/color][/color]
                > . . .[color=green]
                >> I would specify an access modifier explicitly too.[/color]
                >
                > Herfried,
                >
                > Having never used an access modifier in this situation myself,
                > which would you recommend and why?[/color]

                'Public Sub Main'. If you don't specify a modifier, the sub will be
                public too, but it's "good style" to always specify the modifier...

                ;-)

                --
                Herfried K. Wagner [MVP]
                <http://www.mvps.org/dotnet>

                Comment

                • Chris Dunaway

                  #9
                  Re: How to rename sub main to function main

                  On Thu, 12 Feb 2004 10:32:01 +0100, Rody Reulen wrote:
                  [color=blue]
                  > The problem is solved now.
                  >
                  > The reason why it did work was because I did specify:
                  >
                  > Function Main()
                  >
                  > in stead of
                  >
                  > Function Main() as Integer[/color]

                  If Option Strict On was set, it should have flagged it as an error. Is
                  Option Strict On?

                  --
                  Chris

                  To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
                  address.

                  Comment

                  Working...