How to rename sub main to function main

R

Rody Reulen

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
 
H

Herfried K. Wagner [MVP]

* "Rody Reulen said:
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.
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

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" <[email protected]> escribió en el mensaje | 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
 
R

Rody Reulen

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
 
H

Herfried K. Wagner [MVP]

* "Rody Reulen said:
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.
 
P

Phill. W

Herfried K. Wagner said:
* "Rody Reulen" <[email protected]> scripsit: .. . . .. . .
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.
 
H

Herfried K. Wagner [MVP]

* "Phill. W said:
. . .

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...

;-)
 
C

Chris Dunaway

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How to make a splash from is sub main? 1
Shared Sub Main 10
Sub Main() refusing to work 16
VS2005-VB Viewing 'Main' for MDIParent 1
Sub Main() 7
Program and Sub Main 1
Sub Main Not Found 2
sub Main 12

Top