What's wrong with this simple code? I copied if from my text book

  • Thread starter Thread starter david
  • Start date Start date
D

david

When I build this code in Visual Studio 2005 I get and error saying: " 'Sub Main' was not found in 'ConsoleApplication2.Module1' "
" . Sub Main is there. In the online help is said is either missing or not in the correct location. I moved it to the top and it made no difference.

Imports System
Module SpillTheBeans
Private name As String
Private age As Integer
Public Sub DisplayData()
Console.WriteLine("{0} is {1}", name, age)
End Sub
Public Function GetDescription(ByVal age As Integer) As String
If age < 18 Then
Return "Minor"
Else
Return "Adult"
End If
End Function
Public Sub main()
name = "Betty"
age = 24
DisplayData()
Dim Descr As String = GetDescription(age)
Console.WriteLine("{0} is a {1}", name, Descr)
End Sub
End Module
 
Set your startup object to SpillTheBeans.
To do this, double-click on your project
to show the project properties, then pick the
Application tab. Under "Startup object",
select SpillTheBeans. This is the module
containing the main routine.

I figured this out by putting your code in
a new application. Then when the error on
the build came up,I double-clicked on it,
and it came up and asked me to pick the
namespace and module containing the main
sub. Double-clicking on those errors can
be illuminating and helpful, just FYI.

Robin S.
 
David,

Did you create your project at startup as console project.
Than you won't have this trouble, it is a little bit not done well in my
idea in VB 2005, in 2002/3 version there was no problem.

You know that there is a special newsgroup for VB.Net problems.

microsoft.public.dotnet.languages.vb

Cor
 
Back
Top