468,248 Members | 1,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,248 developers. It's quick & easy.

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


Nov 20 '05 #1
8 3299
* "Rody Reulen" <rr*****@romacel.nl> scripsit:
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.


Post the code you are using.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
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" <rr*****@romacel.nl> escribió en el mensaje news:40***********************@dreader14.news.xs4a ll.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

Nov 20 '05 #3
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:

http://msdn.microsoft.com/library/de...sicModules.asp

and

http://msdn.microsoft.com/library/de...helloworld.asp

Hope this helps
Jay

"Rody Reulen" <rr*****@romacel.nl> wrote in message
news:40***********************@dreader14.news.xs4a ll.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

Nov 20 '05 #4
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" <rr*****@romacel.nl> wrote in message
news:40***********************@dreader14.news.xs4a ll.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

Nov 20 '05 #5
* "Rody Reulen" <rr*****@romacel.nl> scripsit:
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.


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

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
* "Rody Reulen" <rr*****@romacel.nl> scripsit: .. . .
Function Main() as Integer .. . . Return <integer value>
End Function

.. . . I would specify an access modifier explicitly too.


Herfried,

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

Regards,
Phill W.
Nov 20 '05 #7
* "Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> scripsit:
. . .
Function Main() as Integer . . . Return <integer value>
End Function

. . .
I would specify an access modifier explicitly too.


Herfried,

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


'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>
Nov 20 '05 #8
On Thu, 12 Feb 2004 10:32:01 +0100, Rody Reulen wrote:
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


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.
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Alvaro Puente | last post: by
2 posts views Thread by Jason | last post: by
1 post views Thread by Jay at SCA | last post: by
8 posts views Thread by Merlin | last post: by
3 posts views Thread by ehabaziz2001 | last post: by
12 posts views Thread by mantrid | last post: by
6 posts views Thread by shuaishuaiyes | last post: by
1 post views Thread by dsrawat | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.