newbie needhelp:'submain' was not found in 'test.module1'

G

Guest

I've just started learning vb.net. Now I'm reading O'reilly programming
vb.net 2nd edition. I have a problem with code example on chapter 6 about
inherits content. I even copied this code into VS studio and compiled. But it
said:
'submain' was not found in 'test.module1'
Although there is already submain in the code.
The code I mentioned above is as follow:

Option Strict On
Imports System
Public Class Window

' constructor takes two integers to
' fix location on the console
Public Sub New(ByVal top As Integer, ByVal left As Integer)
Me.top = top
Me.left = left
End Sub 'New

' simulates drawing the window
Public Overridable Sub DrawWindow( )
Console.WriteLine("Window: drawing Window at {0}, {1}", top, left)
End Sub 'DrawWindow

' these members are protected and thus visible
' to derived class methods. We'll examine this
' later in the chapter
Protected top As Integer
Protected left As Integer

End Class 'Window

' ListBox derives from Window
Public Class ListBox

Inherits Window

' constructor adds a parameter
Public Sub New(ByVal top As Integer, ByVal left As Integer, ByVal
contents As String)
MyBase.New(top, left) ' call base constructor

listBoxContents = contents
End Sub 'New

' an overridden version (note keyword) because in the
' derived method we change the behavior
Public Overrides Sub DrawWindow( )
MyBase.DrawWindow( ) ' invoke the base method
Console.WriteLine( _
"Writing string to the listbox: {0}", listBoxContents)
End Sub 'DrawWindow

Private listBoxContents As String ' new member variable

End Class 'ListBox

Public Class Button

Inherits Window

Public Sub New(ByVal top As Integer, ByVal left As Integer)
MyBase.New(top, left)
End Sub 'New

' an overridden version (note keyword) because in the
' derived method we change the behavior
Public Overrides Sub DrawWindow( )
Console.WriteLine( _
"Drawing a button at {0}, {1}" + ControlChars.Lf, top, Left)
End Sub 'DrawWindow

End Class 'Button

Public Class Tester

Shared Sub Main( )
Dim win As New Window(1, 2)
Dim lb As New ListBox(3, 4, "Stand alone list box")
Dim b As New Button(5, 6)

win.DrawWindow( )
lb.DrawWindow( )
b.DrawWindow( )

Dim winArray(3) As Window
winArray(0) = New Window(1, 2)
winArray(1) = New ListBox(3, 4, "List box in array")
winArray(2) = New Button(5, 6)

Dim i As Integer
For i = 0 To 2
winArray(i).DrawWindow( )
Next i

End Sub 'Main

End Class 'Tester

Could anyone tell me indetail that where and how I must fix above code.
Please help me.
Ineedyour help.
many thanks
 
G

Guest

You have sub main in a class for one thing. I would put sub main in a
separate module and set the start-up as sub main using the Project menu -
Properties.
 
G

Guest

Thanks for your reply.
I'm just started learning vb.net and it's actually my first language to
learn so i have no experience on it. May I bother you, but could you write a
bit more detail about the way I have to follow to correct it?
example: delete this words and add more that codes or something like that.
many thanks.
 
B

Brian Henry

there's nothing wrong with putting a sub main in a class as long as the sub
main is a shared method of the class
 
H

Herfried K. Wagner [MVP]

thecuongjapan said:
I've just started learning vb.net. Now I'm reading O'reilly programming
vb.net 2nd edition. I have a problem with code example on chapter 6 about
inherits content. I even copied this code into VS studio and compiled. But
it
said:
'submain' was not found in 'test.module1'

Double-click the error message in the task list and select the class
containing the 'Sub Main'.
 
C

Cor Ligthert

Hi,

When you want to test something than there should always be something that
runs the program.

In a VBNet form is an automatic Sub "sub main". You can set which is the
start up one, in the first tab that shows up when you click on the project
properties (not the solution).

You can as wel create yourself in a shared class or module a Sub Main.
Because of the fact that your code needs at least a Form, I would do it in
your place with a form.

I hope this helps,

Cor'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top