VBScript in a Nutshell by Paul Lomax, Matt Childs, & Ron Petrusha Unconfirmed error reports are from readers. They have not yet been approved or disproved by the author or editor and represent solely the opinion of the reader. If you have technical questions or error reports, you can send them to booktech@oreilly.com. Please specify the printing date of your copy. This page was updated March 17, 2003. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification UNCONFIRMED errors and comments from readers: (16) The 6th line in the last paragraph now reads: ...multiplies by 27.3... It should read: ...multiplies by 25.4... {17} Example 2-2; This example does not work. The following is correct: Input Inches: {37} The variable declaration for the Null subtype now reads: dim myVarOne, myVarTwo, myVar Three It should read: dim myVarOne, myVarTwo, myVarThree (48) 2nd paragraph; May 2000 Printing "For example, the following code from Global.asa amakes the . . ." should read "For example, the following code from Global.asa makes the . . ." (49) 3rd paragraph-end of code snippet; The right pointing arrow should be an HTML end-of-comment (-->) {57} Sidebar at top of page; The statement that UDTs are missing might be accompanied by a mention of the Dictionary object described on page 220. I think this could be used as a UDT substitute. (58) Next to last line of code in example on page; - - May 2000 Printing - - Reads: For iCtr = COUNTRY TO HAZARDS Should read: For iCtr = COUNTRY to HAZARDS to be consistant with capitialization convention for constants {74} First paragraph under "Launching the Script Debugger" subheading; This paragraph states that, "The Script Debugger is not a standalone application in the sense that you can launch it on its own." {83} First paragraph of the description of the Number property; The text states that, "The Number property is an integer value that contains an error code value between 0 and 65535..." This is incorrect; in fact (as is stated elsewhere in the book), this property may hold any 32-bit (or Long) value. It may be that VBScript itself will never set an error code larger than 65535, but a COM component may very well do so. (92) 2nd sentence of 1st paragraph under the RUNAT="Server" block; Printed: or the ... tags of an ASP document. Should read: or the ... tags of an ASP document. (96) 3rd paragraph under the Response object header; The print version I have is listed as [9/00]. Under the Response object header is a list of Members of the Response Object. The 3rd one listed is "BinaryWriteMethod." The description states, "Writes information directly to the response body without any character converstion." "converstion" be changed to "conversion". {118} In the last code sample, the 1st line of code currently reads: blnHasKeys = Response.Cookies("Colors").HasKeys It should read: blnHasKeys = Request.Cookies("Colors").HasKeys [136] First paragraph of description of CreateObject; The statement, "...strPrefix is an optional string that instructs WSH to trap the object's events (if it has any) and to fire event handlers whose names begin with strPrefix followed by an underscore, followed by the event name." is incorrect. In fact, no underscore is used; the strPrefix and the event name must be directly concatenated. [137] Description of GetObject method; I recently reported an erratum in the description of the CreateObject method on page 136. This concerns the incorrect statement that an underscore must be used to join the strPrefix with the event name. I now realize that this same error applies here to the description of GetObject. (138) Table 7-5 headings; Type and Name headings (or columns) are reversed [138] Table 7-5 Item's Description is incorrect; The decription indicates that you can use an integer index to access one of the environment variable name/value pairs. This is not correct, you can only access a value via the Item property using the varible's name, for example "PATH". [This also true for default access]. In order to iterate through the list of name/value pairs you need to "enumerate" the object created with the: Set wsh = WScript.CreateObject("WScript.Shell") command. This is [of course] done as follows in vbScript: for sPair in wsh 'do something with this name/value pair next It would be valuable to correct the above and mention how to iterate. As a new user I spent a lot of time figuring this out. (139) 4th Method; The correct name of the method is EnumPrinterConnections, which is plural. The printed copy is EnumPrinterConnection, which is singular. In the description section, at the end of the paragraph, "the collection returned....", should be "The collection returned...". (148) Table 7-22: Under the "Key" heading, the values "My Documents" and "Start Menu" should read "MyDocuments" and "StartMenu" respectively (i.e., no spaces). (148) Table 7-22; The problem I see is that Table 7-22 shows the SpecialFolders Collections, but it does not show the Temporary folder as one of them, which it is. I don't know if this is a typo, because it does have the Templates Folder listed. (185) line 13; "As Variant" isn't accepted by my version of CScript [208] The second bullet under CSng Function, Rules at a Glance, now reads: If the value of expression is outside the range of the double datatype, an overflow error is generated. It should read: If the value of expression is outside the range of the single datatype, an overflow error is generated. (209) CStr Function Example ; Is "Dim sMyString as String". Should be "Dim sMyString" (282) second bullet item from bottom; If ofs.FileExists(... should read: If ofs.FolderExists(... {241} First entry in table at the bottom of the page; The entry that reads "End Terminates program execution" should be removed. As is clearly stated in the text, this form of End statement is not supported in VBScript. {316} The first bullet under "Rules at a Glance" now reads: If maximum_value is greater than initial_value... It should read: If initial_value is greater than maximum_value... {316} The first line of the example now reads: For i = LBound(sArray) to LBound(sArray) Step - 1 It should read: For LBound(sArray) to UBound(sArray) Step - 1 [343] IsEmpty Function, Rules at a Glance:; Book states "If the variant passed to IsEmpy has been initialized, True is returned; otherwise, IsEmpty returns False." In my experience, True is returned if the variant is uninitialized, so an If IsEmpty statement will execute if the variant is empty. [354] second sentence; The 2nd line now reads: The first character in the search string is at position 1 It should read: The first character in the sentence is at position 0 (zero) cfr: http://msdn.microsoft.com/library/default.asp?url=/library/en- us/script56/html/vsprofirstindex.asp The FirstIndex property uses a zero-based offset from the beginning of the search string. In other words, the first character in the string is identified as character zero (0). [367] 2nd para under heading "VBA/VBScript Differences"; The paragraph reads: "Once you enable error handling with the On Error Resume Next statement, VBScript provides no means to disable it. This contrasts with VBA, in which the On Error Goto 0 statement disables error handling." This incorrect. VBScript does support the On Error Goto 0 statement to disable error handling. {391} The Syntax description for RegExp.Replace.Method now reads: RegExp.Replace(string1, string1) It should read: RegExp.Replace(string1, string2) [436] UBound Function Syntax; The description of the "arrayname" argument to UBound asserts that it must be the name of an array. This is not true! All it needs to be is an array. It may be referenced by name or in some other way. For example, "UBound(Array(1,2,3))" works just fine. (This example is, of course, not a useful one!) (451) In the section "Date and Time," the Day function says that it returns the day of week when in fact it returns the day of the month. (465) First table; "vbMsgBoxSetForeground" is broken between two lines. As a result, the two pieces should be hyphenated as has been done with, for example, "vbMsgBoxRtlReading" immediately above. There are two more similar instances of missing hyphenation in the table at the bottom of page 463. [465] Table at bottom; "vbNullString" is defined as equating to the value "Zero Length String". This is seriously incorrect. Microsoft's own documentation states that, it is "Not the same as a zero-length string (""); used for calling external procedures." In fact it is a NULL pointer. <490> last entry for 'RegExp'; the 'RegExp.Text' method entry should be 'RegExp.Test'