Permalink
Cannot retrieve contributors at this time
| description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||
|---|---|---|---|---|---|---|---|---|---|
|
Learn more about: BC30420: ‘Sub Main’ was not found in ‘<name>’ |
‘Sub Main’ was not found in ‘<name>’ |
07/20/2015 |
|
|
a006d57d-4dd3-46a7-9026-ca9a31470da7 |
Sub Main is missing, or the wrong location has been specified for it.
Error ID: BC30420
To correct this error
-
Supply the missing
Sub Mainstatement, or if it exists, move it to the appropriate location in the code. For more information onSub Main, see Main Procedure in Visual Basic. -
Specify the location of the project’s startup object in the Startup form box of the Project Designer.
See also
- Sub Statement
- Main Procedure in Visual Basic
- Remove From My Forums
-
Question
-
Okay, another question somewhat releated to my previous post, but I feel that it is worthy of a seperate thread.
Code Block
Module mainModule
Sub Main(ByVal args() As String)
MsgBox(«Hello Workd»)
End Sub
End ModuleWhen i type the following into the cmd prompt to compile
vbc.exe mainModule.vb /main:MainModule.vb
I get the following error
vbc : error BC30420: ‘Sub Main’ was not found in ‘mainmodule.vb’.
Why is it saying that no ‘Sub Main’ was not found when it is there?
Answers
-
Try to change the startup from Project -> Properties -> Debug Section. Hope it solves your problem
-
Code Block
Module mainModule
Sub Main()
MsgBox(«Hello Workd»)
End Sub
End Modulethis will fix your problem
-
Use the following
vbc.exe mainModule.vb
This will compile or work
or if you want to use the /main switch then use the following. The last .vb you previously had used is screwing things up. It is looking for a class name not a filename — hence the .vb is the filename not the classname.
So the following will work
vbc.exe mainModule.vb /main:MainModule
|
Аня_Самойлова 0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
||||
|
1 |
||||
|
01.10.2018, 19:04. Показов 7923. Ответов 10 Метки ООП (Все метки)
__________________
0 |
|
XIST 1274 / 979 / 137 Регистрация: 01.10.2009 Сообщений: 3,092 Записей в блоге: 1 |
||||
|
01.10.2018, 19:31 |
2 |
|||
|
Аня_Самойлова, так его и нету
0 |
|
0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
|
|
01.10.2018, 19:42 [ТС] |
3 |
|
На строчке 72 же объявляется
0 |
|
1274 / 979 / 137 Регистрация: 01.10.2009 Сообщений: 3,092 Записей в блоге: 1 |
|
|
01.10.2018, 19:46 |
4 |
|
Аня_Самойлова, именно в базовом классе его нет
0 |
|
ovva 4201 / 3354 / 813 Регистрация: 02.02.2013 Сообщений: 3,254 Записей в блоге: 2 |
||||
|
01.10.2018, 19:49 |
5 |
|||
|
Вынесите определение класса за границы модуля.
Если вы хотите непосредственно использовать класс КлассТовар то он не может быть MustInherit (к тому же определенные наследники нигде далее не используются).
0 |
|
0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
|
|
01.10.2018, 19:56 [ТС] |
6 |
|
ту же ошибку показывает(
0 |
|
4201 / 3354 / 813 Регистрация: 02.02.2013 Сообщений: 3,254 Записей в блоге: 2 |
|
|
01.10.2018, 20:07 |
7 |
|
Выложите ваш проект целиком.
0 |
|
4201 / 3354 / 813 Регистрация: 02.02.2013 Сообщений: 3,254 Записей в блоге: 2 |
|
|
01.10.2018, 20:24 |
8 |
|
Пример
0 |
|
Аня_Самойлова 0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
||||
|
01.10.2018, 20:48 [ТС] |
9 |
|||
Добавлено через 20 минут
0 |
|
4201 / 3354 / 813 Регистрация: 02.02.2013 Сообщений: 3,254 Записей в блоге: 2 |
|
|
01.10.2018, 20:58 |
10 |
|
Файл не открывается к сожалению Не открывается приложенный файл? Этот файл zip-архив, можно открыть любым архиватором. Внутри vb проект ConsoleApplication1 (загружается через файл ConsoleApplication1.sln).
0 |
|
0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
|
|
01.10.2018, 21:17 [ТС] |
11 |
|
эту проблему я решила)) файл что вы отправили действительно работает. Я постараюсь отправить свой zip
0 |
It’s actually a bit more complicated, and I fear you may have learned the wrong lesson from what DB suggested, useful though it may be.
As you might expect, every program has to know where to start. No matter what you write, it ends up being a series of VERY simple instructions, because that’s all that the CPU can do. All that higher level languages do is make it easier to create complex programs, but they all end up as a series of sequential instructions. You can see them as a stack of cards. When the program begins, it takes the first card from the stack and does what is on the card, then takes the next card from the stack and so on. It’s not quite that simple, as it can keep going back to earlier places in the stack and repeating steps, or even create a second process and move a selection of the cards over to that separate process so that both are going through their stacks of cards at the same time.
However, there always has to be that first card. By long standing tradition, that is Sub Main(). For a very long time, you could ALWAYS find Sub Main(), and that would be roughly where things started (some memory could be set up ahead of time, but nothing much). The first line in Sub Main was the first card in the stack.
With Windows programming in .NET, there is ALWAYS a Sub Main….but you can’t ALWAYS find it. You used to be able to, back in .NET 2002 and 2003, but since then it could be hidden. Windows programs usually begin with a startup form, in which case you’d have a hard time finding Sub Main, if you even can.
What DB showed you is the style that Windows applications had to follow back in 2002 and 2003, and which is still used for console apps as he demonstrated. If you create a Windows application rather than a console app, then you’ll have a startup form (which is usually the first one given to you, by default, though you are free to change that), and neither the module nor the Sub Main is necessary. In that case, the code you had would be fine as you had it, but you’d also have a startup form, which would hide the Sub Main from you.
A class library is a dll. You’ve doubtless seen a few items with that extension. The key point about a dll is that it doesn’t have a Sub Main, plain or hidden. Therefore, you can’t execute a dll because there is no starting point in it. Using the stack of cards analogy, you could say that a dll is one or more stacks of cards, but none of them is the first one. That type of project holds code and objects that will be used by one or more other projects. They can’t stand alone, because they can’t start on their own. They have to be included into some project that actually has a starting point. Once included in, they can be used by that other project. Typically, you create a dll to store methods and objects that you feel you’ll be able to use in multiple projects, though there are other uses for them, as well.
So, don’t feel that you MUST have a module and a Sub Main. You must have one for a console app, but need not write either one for a Windows forms app, and can’t have a meaningful Sub Main for a class library.
It’s safe to say that Visual Basic has become one of the hardest languages to find content about online ever since Microsoft announced that there won’t be any more features added to it in .NET CORE/ .NET 5.
“ Going forward, we do not plan to evolve Visual Basic as a language ”
.NET Team
That explained a lot when I tried to troubleshoot an error I’d gotten and the whole of the internet was almost blank, for an error I’d call trivial and noob level. I’ve recreated the above error so as to show you how to solve it. Save you time.

Every time I tried the compile and run the project, i got and error that the Sub Main()
was not found.
The solution to this is to check that the startup form isn’t referencing to an old method. You can find that in your project properties.
- All you have to do is right-click on your main project in the top-right area of the visual basic working area.

- Scroll to the bottom and click on properties.

On the new window right at the Startup Project section is where you’re going to change from
Sub Main
to the name of your Form.

Once you’re done, you can exit that tab and re-run your project.

Everything should be working fine and you can notice that the error is gone.
Conclusion
Every day is a coding challenge. If you feel that the content was inadequate please comment about it or contact me. Keep coding. Cheers !!
- Remove From My Forums
-
Question
-
Okay, another question somewhat releated to my previous post, but I feel that it is worthy of a seperate thread.
Code Block
Module mainModule
Sub Main(ByVal args() As String)
MsgBox(«Hello Workd»)
End Sub
End ModuleWhen i type the following into the cmd prompt to compile
vbc.exe mainModule.vb /main:MainModule.vb
I get the following error
vbc : error BC30420: ‘Sub Main’ was not found in ‘mainmodule.vb’.
Why is it saying that no ‘Sub Main’ was not found when it is there?
Answers
-
Try to change the startup from Project -> Properties -> Debug Section. Hope it solves your problem
-
Code Block
Module mainModule
Sub Main()
MsgBox(«Hello Workd»)
End Sub
End Modulethis will fix your problem
-
Use the following
vbc.exe mainModule.vb
This will compile or work
or if you want to use the /main switch then use the following. The last .vb you previously had used is screwing things up. It is looking for a class name not a filename — hence the .vb is the filename not the classname.
So the following will work
vbc.exe mainModule.vb /main:MainModule
- Remove From My Forums
-
Question
-
Okay, another question somewhat releated to my previous post, but I feel that it is worthy of a seperate thread.
Code Block
Module mainModule
Sub Main(ByVal args() As String)
MsgBox(«Hello Workd»)
End Sub
End ModuleWhen i type the following into the cmd prompt to compile
vbc.exe mainModule.vb /main:MainModule.vb
I get the following error
vbc : error BC30420: ‘Sub Main’ was not found in ‘mainmodule.vb’.
Why is it saying that no ‘Sub Main’ was not found when it is there?
Answers
-
Try to change the startup from Project -> Properties -> Debug Section. Hope it solves your problem
-
Code Block
Module mainModule
Sub Main()
MsgBox(«Hello Workd»)
End Sub
End Modulethis will fix your problem
-
Use the following
vbc.exe mainModule.vb
This will compile or work
or if you want to use the /main switch then use the following. The last .vb you previously had used is screwing things up. It is looking for a class name not a filename — hence the .vb is the filename not the classname.
So the following will work
vbc.exe mainModule.vb /main:MainModule
