Solved

VS Studio .NET environment and VB.NET compile error: Sub Main was not found

Posted on 2007-04-05
5
389 Views
Last Modified: 2013-11-26
I'm trying to write a very simple console exe in vb.net. I have written the .vb file and opened it inside Visual Studio .NET but it seems I can't compile from within here without defining a project for my solution. (Is that correct?)

And if I try to add a project, all the available ones are in C# which I don't want to code in.

So I instead run the command line compiler, vbc, to compile my simple little .vb file:
vbc /out:c:/hello.exe /t:exe c:/"vbnet/Hellovb"

BUT IT DOESN'T compile, annoyingly.. It says "Sub Main was not found in 'Hello'"

Here is my code:
Imports System
Imports System.Data
Imports System.Console
Module MyApp
Sub Main()
Dim obj As Class1 = New Class1
System.Console.WriteLine(obj.Method1)
System.Console.ReadLine()
End Sub
End Module

Class Class1
Function Method1() As String
Return "Hello Experts Exchange"
End Function
End Class

What the heck is going on???

Thank you!
0
Comment
Question by:rss2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Jason Evans
ID: 18856908
Hi there.

If you go to the properties window for your project, select the 'Application' tab. Make sure that the combobox 'Startup object' contains 'Sub Main', if not then go to that option and change it manually.

There reason your getting the error is due to VS not knowing where to find Sub Main in the project settings.

Jas.
0
 

Author Comment

by:rss2
ID: 18857236
Ok I wrote the vb file in notepad. I opened up VS and there IS not project for visual basic .net available to select so I just opened an empty solution. But since there is not project, I can't see the application tab.

:(

can you walk me through the steps to creating a VB.NET console app in Visual Studio 2005 or .net framework?
0
 
LVL 10

Accepted Solution

by:
Jason Evans earned 500 total points
ID: 18859922
Hi there.

If you startup Visual Studio 2005 and go to the File menu. Select New, then from the options, choose Visual Basic then Console Application.

When the new project is loaded in VS, go to Solution Explorer and open up Module1.vb. Delete all the code in that file.

Copy the code:

Imports System
Imports System.Data
Imports System.Console

Module MyApp
  Sub Main()
    Dim obj As Class1 = New Class1
    System.Console.WriteLine(obj.Method1)
    System.Console.ReadLine()
End Sub
End Module

Into Module1.vb.

Then got to the Project menu and select Add New Item. From the options, choose Class.

In the class file that appears, delete all the code and paste this into it:


Class Class1
    Function Method1() As String
       Return "Hello Experts Exchange"
    End Function
End Class

In solution explorer, right-click on the new project, and choose Properties from the menu. You will see the project properties window appear. Do the check that I mentioned in my last post about the Application tab.

Hope this helps.
Jas.
0
 
LVL 3

Expert Comment

by:r1937
ID: 18861037
Double click "My Project" on the Solution Explorer, and select "Sub Main"
0
 

Author Comment

by:rss2
ID: 18880818
For some reason when I click on file then "new" there is no Visual Basic option. I have only visual C# and visual c++...

Am I missing a component of my installation of VS .NET 2.0?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question