ok, I have an A level computing exam on Monday, and I have been working on the pre-release skeleton code.
This morning when I tried I got an error saying 'Sub Main' was not found
. There clearly is a Sub Main()
in the code which I will paste in below.
I tried adding another sub main()
before getting a second error saying Sub Main() has multiple definitions
.
I really need to get this sorted, so any help would be greatly appreciated.
Here is the code for the Sub Main() by itself:
Sub Main()
Dim Choice As Char
Dim Deck(52) As TCard
Dim RecentScores(NoOfRecentScores) As TRecentScore
Randomize()
Do
DisplayMenu()
Choice = GetMenuChoice()
Select Case Choice
Case "1"
LoadDeck(Deck)
ShuffleDeck(Deck)
PlayGame(Deck, RecentScores)
Case "2"
LoadDeck(Deck)
PlayGame(Deck, RecentScores)
Case "3"
DisplayRecentScores(RecentScores)
Case "4"
ResetRecentScores(RecentScores)
End Select
Loop Until Choice = "q"
End Sub
And here is the full code if that helps:
'Skeleton Program code for the AQA COMP1 Summer 2014 examination
'this code should be used in conjunction with the Preliminary Material
'written by the AQA COMP1 Programmer Team
'developed in the Visual Studio 2008 (Console Mode) programming environment (VB.NET)
Module CardPredict
Const NoOfRecentScores As Integer = 3
Structure TCard
Dim Suit As Integer
Dim Rank As Integer
End Structure
Structure TRecentScore
Dim Name As String
Dim Score As Integer
End Structure
Sub Main()
Dim Choice As Char
Dim Deck(52) As TCard
Dim RecentScores(NoOfRecentScores) As TRecentScore
Randomize()
Do
DisplayMenu()
Choice = GetMenuChoice()
Select Case Choice
Case "1"
LoadDeck(Deck)
ShuffleDeck(Deck)
PlayGame(Deck, RecentScores)
Case "2"
LoadDeck(Deck)
PlayGame(Deck, RecentScores)
Case "3"
DisplayRecentScores(RecentScores)
Case "4"
ResetRecentScores(RecentScores)
End Select
Loop Until Choice = "q"
End Sub
Sub Main()
Console.Write("Boo")
End Sub
Function GetRank(ByVal RankNo As Integer) As String
Dim Rank As String = ""
Select Case RankNo
Case 1 : Rank = "Ace"
Case 2 : Rank = "Two"
Case 3 : Rank = "Three"
Case 4 : Rank = "Four"
Case 5 : Rank = "Five"
Case 6 : Rank = "Six"
Case 7 : Rank = "Seven"
Case 8 : Rank = "Eight"
Case 9 : Rank = "Nine"
Case 10 : Rank = "Ten"
Case 11 : Rank = "Jack"
Case 12 : Rank = "Queen"
Case 13 : Rank = "King"
End Select
Return Rank
End Function
Function GetSuit(ByVal SuitNo As Integer) As String
Dim Suit As String = ""
Select Case SuitNo
Case 1 : Suit = "Clubs"
Case 2 : Suit = "Diamonds"
Case 3 : Suit = "Hearts"
Case 4 : Suit = "Spades"
End Select
Return Suit
End Function
Sub DisplayMenu()
Console.WriteLine()
Console.WriteLine("MAIN MENU")
Console.WriteLine()
Console.WriteLine("1. Play game (with shuffle)")
Console.WriteLine("2. Play game (without shuffle)")
Console.WriteLine("3. Display recent scores")
Console.WriteLine("4. Reset recent scores")
Console.WriteLine()
Console.Write("Select an option from the menu (or enter q to quit): ")
End Sub
Function GetMenuChoice() As Char
Dim Choice As Char
Choice = Console.ReadLine
Console.WriteLine()
Return Choice
End Function
Sub LoadDeck(ByRef Deck() As TCard)
Dim Count As Integer
FileOpen(1, "deck.txt", OpenMode.Input)
Count = 1
While Not EOF(1)
Deck(Count).Suit = CInt(LineInput(1))
Deck(Count).Rank = CInt(LineInput(1))
Count = Count + 1
End While
FileClose(1)
End Sub
Sub ShuffleDeck(ByRef Deck() As TCard)
Dim NoOfSwaps As Integer
Dim Position1 As Integer
Dim Position2 As Integer
Dim SwapSpace As TCard
Dim NoOfSwapsMadeSoFar As Integer
NoOfSwaps = 1000
For NoOfSwapsMadeSoFar = 1 To NoOfSwaps
Position1 = Int(Rnd() * 52) + 1
Position2 = Int(Rnd() * 52) + 1
SwapSpace = Deck(Position1)
Deck(Position1) = Deck(Position2)
Deck(Position2) = SwapSpace
Next
End Sub
Sub DisplayCard(ByVal ThisCard As TCard)
Console.WriteLine()
Console.WriteLine("Card is the " & GetRank(ThisCard.Rank) & " of " & GetSuit(ThisCard.Suit))
Console.WriteLine()
End Sub
Sub GetCard(ByRef ThisCard As TCard, ByRef Deck() As TCard, ByVal NoOfCardsTurnedOver As Integer)
Dim Count As Integer
ThisCard = Deck(1)
For Count = 1 To (51 - NoOfCardsTurnedOver)
Deck(Count) = Deck(Count + 1)
Next
Deck(52 - NoOfCardsTurnedOver).Suit = 0
Deck(52 - NoOfCardsTurnedOver).Rank = 0
End Sub
Function IsNextCardHigher(ByVal LastCard As TCard, ByVal NextCard As TCard) As Boolean
Dim Higher As Boolean
Higher = False
If NextCard.Rank > LastCard.Rank Then
Higher = True
End If
Return Higher
End Function
Function GetPlayerName() As String
Dim PlayerName As String
Console.WriteLine()
Console.Write("Please enter your name: ")
PlayerName = Console.ReadLine
Console.WriteLine()
Return PlayerName
End Function
Function GetChoiceFromUser() As Char
Dim Choice As Char
Console.Write("Do you think the next card will be higher than the last card (enter y or n)? ")
Choice = Console.ReadLine
Return Choice
End Function
Sub DisplayEndOfGameMessage(ByVal Score As Integer)
Console.WriteLine()
Console.WriteLine("GAME OVER!")
Console.WriteLine("Your score was " & Score)
If Score = 51 Then
Console.WriteLine("WOW! You completed a perfect game.")
End If
Console.WriteLine()
End Sub
Sub DisplayCorrectGuessMessage(ByVal Score As Integer)
Console.WriteLine()
Console.WriteLine("Well done! You guessed correctly.")
Console.WriteLine("Your score is now " & Score & ".")
Console.WriteLine()
End Sub
Sub ResetRecentScores(ByRef RecentScores() As TRecentScore)
Dim Count As Integer
For Count = 1 To NoOfRecentScores
RecentScores(Count).Name = ""
RecentScores(Count).Score = 0
Next
End Sub
Sub DisplayRecentScores(ByVal RecentScores() As TRecentScore)
Dim Count As Integer
Console.WriteLine()
Console.WriteLine("Recent scores:")
Console.WriteLine()
For Count = 1 To NoOfRecentScores
Console.WriteLine(RecentScores(Count).Name & " got a score of " & RecentScores(Count).Score)
Next
Console.WriteLine()
Console.WriteLine("Press the Enter key to return to the main menu")
Console.WriteLine()
Console.ReadLine()
End Sub
Sub UpdateRecentScores(ByRef RecentScores() As TRecentScore, ByVal Score As Integer)
Dim PlayerName As String
Dim Count As Integer
Dim FoundSpace As Boolean
PlayerName = GetPlayerName()
FoundSpace = False
Count = 1
While Not FoundSpace And Count <= NoOfRecentScores
If RecentScores(Count).Name = "" Then
FoundSpace = True
Else
Count = Count + 1
End If
End While
If Not FoundSpace Then
For Count = 1 To NoOfRecentScores - 1
RecentScores(Count) = RecentScores(Count + 1)
Next
Count = NoOfRecentScores
End If
RecentScores(Count).Name = PlayerName
RecentScores(Count).Score = Score
End Sub
Sub PlayGame(ByVal Deck() As TCard, ByRef RecentScores() As TRecentScore)
Dim NoOfCardsTurnedOver As Integer
Dim GameOver As Boolean
Dim NextCard As TCard
Dim LastCard As TCard
Dim Higher As Boolean
Dim Choice As Char
GameOver = False
GetCard(LastCard, Deck, 0)
DisplayCard(LastCard)
NoOfCardsTurnedOver = 1
While NoOfCardsTurnedOver < 52 And Not GameOver
GetCard(NextCard, Deck, NoOfCardsTurnedOver)
Do
Choice = GetChoiceFromUser()
Loop Until Choice = "y" Or Choice = "n"
DisplayCard(NextCard)
NoOfCardsTurnedOver = NoOfCardsTurnedOver + 1
Higher = IsNextCardHigher(LastCard, NextCard)
If Higher And Choice = "y" Or Not Higher And Choice = "n" Then
DisplayCorrectGuessMessage(NoOfCardsTurnedOver - 1)
LastCard = NextCard
Else
GameOver = True
End If
End While
If GameOver Then
DisplayEndOfGameMessage(NoOfCardsTurnedOver - 2)
UpdateRecentScores(RecentScores, NoOfCardsTurnedOver - 2)
Else
DisplayEndOfGameMessage(51)
UpdateRecentScores(RecentScores, 51)
End If
End Sub
End Module
Thanks in advance,
Ed
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 Main
statement, 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
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
Аня_Самойлова 0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
||||
1 |
||||
01.10.2018, 19:04. Показов 8404. Ответов 10 Метки ООП (Все метки)
0 |
XIST 1293 / 994 / 141 Регистрация: 01.10.2009 Сообщений: 3,170 Записей в блоге: 1 |
||||
01.10.2018, 19:31 |
2 |
|||
Аня_Самойлова, так его и нету
0 |
0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
|
01.10.2018, 19:42 [ТС] |
3 |
На строчке 72 же объявляется
0 |
1293 / 994 / 141 Регистрация: 01.10.2009 Сообщений: 3,170 Записей в блоге: 1 |
|
01.10.2018, 19:46 |
4 |
Аня_Самойлова, именно в базовом классе его нет
0 |
ovva 4303 / 3439 / 831 Регистрация: 02.02.2013 Сообщений: 3,335 Записей в блоге: 2 |
||||
01.10.2018, 19:49 |
5 |
|||
Вынесите определение класса за границы модуля.
Если вы хотите непосредственно использовать класс КлассТовар то он не может быть MustInherit (к тому же определенные наследники нигде далее не используются).
0 |
0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
|
01.10.2018, 19:56 [ТС] |
6 |
ту же ошибку показывает(
0 |
4303 / 3439 / 831 Регистрация: 02.02.2013 Сообщений: 3,335 Записей в блоге: 2 |
|
01.10.2018, 20:07 |
7 |
Выложите ваш проект целиком.
0 |
4303 / 3439 / 831 Регистрация: 02.02.2013 Сообщений: 3,335 Записей в блоге: 2 |
|
01.10.2018, 20:24 |
8 |
Пример
0 |
Аня_Самойлова 0 / 0 / 0 Регистрация: 24.08.2018 Сообщений: 60 |
||||
01.10.2018, 20:48 [ТС] |
9 |
|||
Добавлено через 20 минут
0 |
4303 / 3439 / 831 Регистрация: 02.02.2013 Сообщений: 3,335 Записей в блоге: 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 |