Adding Comments to a Script

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Comments are statements that are ignored by the script host when the script runs. To ensure that the script host does not attempt to interpret a comment as a command, you must preface each comment with a comment delimiter. VBScript allows two delimiters: the single quotation mark ( ) and the REM statement. For example, both of the following lines of code are valid comments:

' This is a comment using a single quote delimiter. REM This is a comment using the REM statement as a delimiter. 

Although most script writers use the single quotation mark, you might consider following the single quotation mark with an asterisk when commenting your code:

'* This is another comment. 

This approach has two advantages over the single quotation mark alone. First, it makes the comment stand out from the rest of the text; a single quotation mark by itself can be difficult to see at times. Second, the single quotation mark is a valid VBScript character that has uses beyond delimiting comments. This can be a problem if you use an automated procedure to extract comments from a script; such a procedure might also retrieve items that are not comments. Because you are less likely to use * anywhere else in your script, it makes a good delimiter.

Always include comments on separate lines except for comments that accompany the declaration of a variable. Comments included on the same line as a VBScript statement (end-of-the-line comments) are valid but can be difficult to read. For example, compare the two commenting styles in the following script snippet; in the first half of the script, comments are placed on the same line as a VBScript statement, while in the second half of the script, the comments are placed on separate lines. Most people find it easier to quickly identify the comments used in the second half of the script.

On Error Resume Next Set WshNetwork = WScript.CreateObject("WScript.Network") WshNetwork.MapNetworkDrive "Z:", "\\RemoteServer\Public" '* Map drive Z. If Err.Number <> 0 Then '* Check to make sure the operation succeeded.     Err.Clear     Wscript.Echo "The drive could not be mapped." End If '* Map drive Z. WshNetwork.MapNetworkDrive "Z:", "\\RemoteServer\Public" '* Check to make sure the operation succeeded. If Err.Number <> 0 Then     Err.Clear     Wscript.Echo "The drive could not be mapped." End If 

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net