If you're familiar with all aspects of the VBScript language, you're ready to start incorporating them into your scripts. To help you, I'll provide an example of how you can use VBScript arrays in a script and discuss a potential pitfall if you want to use both VBScript and JScript arrays in a script.
The Example
Suppose you want to create a script that automates server connections. You have a text file that contains a list of servers that you want to connect to one another. In this file, each line contains a server name followed by a carriage-return and linefeed (CR+LF) combination. The servers that you want to include will likely change in the future, so you decide to create a dynamic array. You want each index in this array to contain a server name.
Listing 1 contains a script that reads the server names into a dynamic array called arrText. As Listing 1 shows, you use FileSystemObject (FSO) and TextStream (TS) objects to manipulate the text file. FSO and TS objects are part of the Scripting object model that both VBScript and JScript follow. These objects let you use VBScript code to work with OS files and folders. (I'll cover FSO and TS objects in more detail in a future installment of the "Understanding VBScript series." You can also read about them in Alistair G. Lowe-Norris, "An ADSI Primer, Part 6: Using ADSI to Create and Manipulate User Accounts," June 1999, and Michael Otey, "Using WSH for Windows Automation," December 1998.) . . .
Anonymous User July 13, 2005 (Article Rating: