Re: reading a file that has null or blank field
- From: RdS <RdS@xxxxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 10:36:43 -0800
thanks for your reply.
I understand why it is happening, but I don't know how to handle such an
issue. Isn't there a function that would allow me to handle error?
thanks again.
"ekkehard.horner" wrote:
RdS wrote:.
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"?
No, there aren't NULL values in plain text files processed with
the FileSystemObject. The error results from trying to access
elements from arySourceFields which aren't there because Split()
couldn't create them due to lack of ","s.
The code is as follows:Const UBOUND_EXPECTED = 4 ' 5 items indexed 0 ... 4
set objFSO = CreateObject("Scripting.FileSystemObject")
set objSourceFile = objFSO.OpenTextFile(strSourceFilename, ForReading)
if err <> 0 then ErrHandler
do until objSourceFile.AtEndOfStreamIf UBOUND_EXPECTED <> UBound( arySourceFields ) Then
arySourceFields = split(objSourceFile.ReadLine,",",-1,1)
skip or raise hell
Else
work with all fields
End If
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.
- Follow-Ups:
- Re: reading a file that has null or blank field
- From: ekkehard.horner
- Re: reading a file that has null or blank field
- References:
- Re: reading a file that has null or blank field
- From: ekkehard.horner
- Re: reading a file that has null or blank field
- Prev by Date: Re: check if file open
- Next by Date: Unzip File
- Previous by thread: Re: reading a file that has null or blank field
- Next by thread: Re: reading a file that has null or blank field
- Index(es):
Relevant Pages
|
Loading