hi,
when reading through a CSV file and a field is missing I receive a run time
error. I have the on error resume next commented out for now during
debugging. But, how do I handle if a field is missing when trying to assign
the array? In this case would missing mean "NULL"? The code is as follows:
set objFSO = CreateObject("Scripting.FileSystemObject")
set objSourceFile = objFSO.OpenTextFile(strSourceFilename, ForReading)
if err <> 0 then ErrHandler
do until objSourceFile.AtEndOfStream
arySourceFields = split(objSourceFile.ReadLine,",",-1,1)
if err <> 0 then ErrHandler
wscript.stdout.write arySourceFields(0) '''remove.
loop
.
.
.
Example of csv file contents:
500,world,1,1,5
501,now,2,6,0
.
.
.
600,,,
601
the problem occurs for records like 601 above. notice there are no commas
seperating other fields. the csv just has first field and nothing in
remaining fields like rest of records. Code works fine for all other
instances including 600,,,
Assigning arySourceFields(x) to any variable or simply doing the
stdout.write above causes runtime of:
createfiles.vbs(102,1) Microsoft VBScript runtime error: Subscript out of
range: 'wscript.stdout'
How do I prevent the error from occuring in my code without the on error
resume next? Isn't there a function that would check to see if the subject
is valid?
Thank you.