Solved

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

Posted on 2007-04-05
5
357 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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