Solved

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

Posted on 2007-04-05
5
295 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
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:MrClyfar
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:
MrClyfar 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now