Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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