vbc : error BC30420: 'Sub Main' was not found in 'Product'.

  • Thread starter Thread starter Learner
  • Start date Start date
L

Learner

Hello,

I just wanted to jump on try creating a small calss in VB.NET in a
note pad. And my class takes below lines of code



Public Class Product

Public Name as string
Private m_id as string

Public Sub New()
m_id = 0
End Sub

Public property ID() as Integer

Get
ID = M_id
End Get

Set(byVal Value as Integer)
m_id = Value
End Set

End Property

End Class



But when I run this in the command prompt I got the above error that is
mentioned in the subject line.

Now, my question is do I need to have Sub Main class to create a simple
class? I guess may be I need it when I want create an object for this
Product class and try calling its properties and methods.

Please help me understand.

Thanks
-L
 
Learner said:
I just wanted to jump on try creating a small calss in VB.NET in a
note pad. And my class takes below lines of code

Your application needs an "entry point", where execution starts.

I suggest to add a class with a shared main sub:

\\\
Public Class Program
Public Shared Sub Main()
Console.WriteLine("Hello World")
End Sub
End Class
///
 
Hello,

Thanks for the quick response.

Is this some thing like this?

Public Class Product
Public shared sub Main()
Public Name as string
Private m_id as string

Public Sub New()
m_id = 0
End Sub

Public property ID() as Integer

Get
ID = M_id
End Get

Set(byVal Value as Integer)
m_id = Value
End Set

End Property
End sub
End Class

Can you help modify my program?

Thanks
-L
 
I just tried simply your few lines of code but it said "Console" is not
declared. Do I need to import any kind of namespace?

Thanks
-L
 
Learner said:
I just tried simply your few lines of code but it said "Console" is not
declared. Do I need to import any kind of namespace?

Ooops, yes, I forgot 'Imports System' on top of the file.
 
Back
Top