Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-04-05
5
Medium Priority
?
401 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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