Chapter 2

[New]Page 30, constructor Sub New in the third listing

The Sub New method mistakenly ends with an “End Function” statement. Thanks to Alexandre Mensi for spotting this typo.

[New]Page 32, end of the second paragraph from the bottom of page

The sentence

you can remove it from the list

should read

you can’t remove it from the list

[New]Page 61, Table 2-1

The entry in the table for the Decimal type incorrectly states that this type takes 12 bytes, instead of 16 bytes. Thanks to reader Erwin D'hondt for spotting this typo.

[New]Page 67, first listing

Reader Dan Karmann has done a great job in spotting many typos and mistakes in the book. For example, he noted that this listing doesn’t have much to do with the Is operator (the topic of the section), and that the last two lines in this listing:

Console.WriteLine(s1 = s2)

Console.WriteLine(s1 = s3)

should be modified as follows

Console.WriteLine(s1 Is s2)

Console.WriteLine(s1 Is s3)

I’d like to thank Dan for his observations, many of which are reported in this document, even if I don’t explicitly mention his name.

[New]Page 74, the sentence at the end of page

For example, the binary representation of 134 is 00100010: if you shift this number two digits to the left you get 10001000 (the binary equivalent of 134)

should read:

For example, the binary representation of 34 is 00100010: if you shift this number two digits to the left you get 10001000 (the binary equivalent of 136)

Chapter 3

[New]Page 91, second listing

The Goto statement in the third line points to a label with a space in it (“Skip Action”); the space must be removed (“SkipAction”).

[New]Page 92, second listing

The last line of this listing should read

ProcTwo(Cint(qty), msg.ToString())

[New]Page 115, second listing

The first Catch clause should be emphasized in boldface, to match the description at the end of the text paragraph that precedes it:

Try

' Do something

Catch ex As Exception When LogException(ex)

' No code here

[New]Page 116, first listing

The description of how this code behaves isn’t completely accurate. A reader brought to my attention that the second message “Inside CheckException function” message is actually caused by the fs.Close() method in the innermost Finally block, which attempts to invoke a method on a variable that is Nothing. The code should be fixed as follows:

Finally

Console.WriteLine("Inside inner Finally block")

' Close the file here

If fs IsNot Nothing Then fs.Close()

Chapter 4

[New]Page 156, listing, 6th line from bottom of page

The following line:

Public Sub New(ByVal $Fieldname$ As $FieldType)

lacks a terminating dollar sign for FieldType and should read:

Public Sub New(ByVal $Fieldname$ As $FieldType$)

Chapter 5

[New]Page 188, the first non-bulleted paragraph

The text explains that you can test only functions in modules from inside the Command window. Reader Eric Moreau noticed that this isn’t accurate, because you can also test Sub methods (just enter the name without the ‘?’) and Shared methods in forms and classes.

[New]Page 213, first listing

First line incorrectly uses the AndAlso operator, where the OrElse operator is the correct one:

If actual < -10 OrElse actual > 10 Then

Chapter 6

Page 266, the paragraph before the note

Code in one portion of the type can freely reference members defined in another portion, as is the case with the FirstName and LastName fields in Employee_2.vb assigned from inside the constructor in Employee_2.vb.

The constructor that assigns the fields is in Employee_1.vb, hence the paragraph becomes:

Code in one portion of the type can freely reference members defined in another portion, as is the case with the FirstName and LastName fields in Employee_2.vb assigned from inside the constructor in Employee_1.vb.

Chapter 8

Page 321, a missing “not” in the following paragraph reverses the actual sense

Because the redefined method in the derived class is related to the original method in the base class, the two members can have different scope qualifiers,

Should read:

Because the redefined method in the derived class is not related to the original method in the base class, the two members can have different scope qualifiers,

Also, the paragraph that precedes the “Redefining Static Members” headline, mentions the MustOverridable keyword, which doesn’t exist. The correct keyword is, of course, MustOverride.

[New]Page 322, the “Sealed and Virtual Classes” headline

There is a typo in the headline, which should read

Sealed and Abstract Classes

Chapter 11

[New]Page 418, second listing

The second overload of the Contains method should read as follows:

Public Function Contains(ByVal obj As T2) As Boolean

Return Me.Object2 Is obj

End Function

Chapter 13

[New]Page 528, second listing

The last line of this listing should be replaced as follows

persons.InsertRange(0, arr)

[New]Page 531, second listing

The 2nd line of this listing should be replaced as follows

dictPersons.Add("John Evans", New Person("John", "Evans")

Page 540, listing of the MinMaxCollection

The SetItem method has a bug; the RemoveItem method can be made more concise. Here are the correct versions:

Protected Overrides Sub SetItem(ByVal index As Integer, ByVal item As T)

If min.CompareTo(Me(index)) = 0 OrElse _

max.CompareTo(Me(index)) = 0 Then upToDate = False

MyBase.SetItem(index, item)

End Sub

Protected Overrides Sub RemoveItem(ByVal index As Integer)

If min.CompareTo(Me(index)) = 0 OrElse _

max.CompareTo(Me(index)) = 0 Then upToDate = False

MyBase.RemoveItem(index)

End Sub

Chapter 14

[New]Page 575: listing of the Evaluate method.

The definition of the “num” constant isn’t accurate and should be replaced by the following code:

' A floating point number, with optional leading and trailing spaces

Const num As String = "\s*[+-]?\d+(\.\d+)?\b(?!\.)\s*"

Page 577: listing of the PerformOperation method.

The following two lines refer to a group that doesn’t exist and can be deleted

ElseIf m.Groups("neg").Length > 0 Then

Return "+"

Chapter 15

Page 614: listing at the top of the page

The following Console.Line method contains the string “Location”, but the output produced by the code, which appears immediately afterwards, uses the string “City”.

Do Until parser.EndOfData

Dim fields() As String = parser.ReadFields()

Console.WriteLine("First={0}, Last={1}, Location={2}", fields(0), fields(1), fields(2))

Loop

To have the output match the code, the latter should be changed into

Do Until parser.EndOfData

Dim fields() As String = parser.ReadFields()

Console.WriteLine("First={0}, Last={1}, City={2}", fields(0), fields(1), fields(2))

Loop

Chapter 16

[New]Page 635: last line in table 16-2.

The OpenTextFileWriter returns a StreamWriter object, not a StreamReader as incorrectly reported in text.

[New]Page 671: listing

The only listing in this page mentions a compilation constant named _MYAPPLICATIONBASE, which doesn’t exist. That line should read:

_MyType="Custom", _MYAPPLICATIONTYPE="WindowsForms”, _MYFORMS=True

Chapter 17

Page 694: the only listing in the page

This listing has two statements, but only the first one is relevant to the discussion

MessageBox.Show(My.Resources.MsgText, My.Resources.MsgTitle)

Chapter 19

[New]Page 789: first listing

The newline character preceding the declaration of the Name field has been mistakenly deleted. The following declaration should go in separate lines

Public ReadOnly Group As String = ""

Public Name As String = ""

Chapter 20

Page 851, the paragraph before the listing

This paragraph mentions “relevant statements in bold type”, yet there are no bold lines in the listing the follows. Please ignore this sentence.

[New]Page 872: listing, btnStop_Click method

The following statement:

BackgroundWorker1.RunWorkerAsync(argument)

Should read

BackgroundWorker1.CancelAsync()

Page 900, the paragraph following “The ISerializationSurrogate Interface” headline

The following sentence has a typo:

The ISerialization interface enables you to define a custom serialization process

And should read as follows:

The ISerializable interface enables you to define a custom serialization process

Chapter 21

Page 891, last two listings

These listings incorrectly pass the string values “FirstValue” and “LastValue” to the GetValue and GetString methods. These strings should be corrected into “FirstName” and “LastName”, respectively. Therefore, the two listings become:

Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)

' Retrieve serialized fields.

Me.FirstName = CStr(info.GetValue("FirstName", GetType(String)))

Me.LastName = CStr(info.GetValue("LastName", GetType(String)))

' A more concise way to retrieve the FirstName value

Me.FirstName = info.GetString("FirstName")

End Sub

Page 896, second listing should read as follows

Sub GetObjectDataHelper(ByVal info As SerializationInfo, _

ByVal context As StreamingContext, ByVal obj As Object)

' Get the list of serializable members.

Dim members() As MemberInfo = GetSerializableMembersEx(obj.GetType)

End Sub

Public Sub ISerializableConstructorHelper(ByVal info As SerializationInfo, _

ByVal context As StreamingContext, ByVal obj As Object)

' Get the list of serializable members for this object.

Dim members() As MemberInfo = GetSerializableMembersEx(obj.GetType)

End Sub

[New]Page 896: listing spanning this and next page

OnSerializing, OnSerialized, OnDeserializing, and OnDeserialized attributes have been incorrectly embedded in square brackets (as they are in C#) instead of angular brackets (as attributes are specified in VB).

[New]Page 903: second listing

Both the GetObjectData and SetObjectData methods contain the following statement:

Dim flags As BindingFlags = BindingFlags.Instance Or _

BindingFlags.Public Or BindingFlags.Public

where the Public bit is repeated. Instead, both these statements should be replaced by:

Dim flags As BindingFlags = BindingFlags.Instance Or _

BindingFlags.Public Or BindingFlags.NonPublic

Page 905, a typo makes the following comment quite misleading

' Save directory if field's type is serializable.

It should read:

' Save directly if field's type is serializable.

Chapter 22

Page 914, first paragraph

The DefaultCharSet attribute is described as an assembly-level attribute, which isn’t correct. This attribute can be specified only at the module level, therefore the code sample becomes:

' Change the default CharSet value from Ansi to Auto.

<Module: DefaultCharSet(CharSet.Auto)>

Page 942, first paragraph: the following sentence

For example, a type named Animal.Mammal.Mouse is exported to a coclass named Mouse.When a name collision would result—for example, because another class is named Hardware.Peripheral.Mouse—the type is exported with its full name, but periods are replaced by underscores.

should read as follows:

For example, a type named Animal.Mammal.Mouse is exported to a coclass named Animal.Mouse. When a name collision would result—for example, because another class is named Animal.Rodent.Mouse—the type is exported with its full name, but periods are replaced by underscores.

Page 946, last listing: the ComUnregisterFunction attribute is mistakenly omitted

<ComUnregisterFunction()> _

Private Shared Sub UnRegister(ByVal ty As Type)

Registry.CurrentUser.DeleteSubKey(COMPANYKEY)

End Sub