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
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