Processing the CSV file's fields. After the HTA verifies that
the file exists, it executes the getFields function. As Listing
2 shows, the getFields function populates the fields array (a global
variable) with the field names from the CSV file. The function uses the FileSystemObject's
Open-TextFile method to open the CSV file and read its first line, then closes
the CSV file. Next, it empties the fields array by setting its length
property to zero. The function uses the split method to return an array of substrings,
using the comma (,) character as a delimiter. Be aware that the get-Fields function
uses the split method to parse the first line of the CSV file, so the function
will fail if a field name contains a comma (even if it's enclosed in quotes).
The getFields function then uses the for statement to iterate the array
of substrings that the split method creates. If the useHeader function returns
true (which will be the case if you've selected the check box), the function
uses the replace method to remove any double-quote (") characters from
the field name. Next, the function determines whether the field name contains
the colon (:) character, indicating a field type. (I'll discuss field types
in a moment.) If the field name contains a colon, the getFields function removes
the colon and the remainder of the string so that only the field name is added
to the fields array. For example, if the field is named Size:Int, the
fields array will contain only Size (the :Int is not part of the
field's name). . . .
KWhite December 19, 2006 (Article Rating: