vbscript: Spilt Issue
My text files are delimited as follows:
Record Delimiter: vbCRLF
Field Delimiter: ~
I need to break each record apart based on the first field which defines the type of record (ex: LIN contains the part number as the 4th field ).
When I run my script I continue to get a Type Mismatch error relating to the arrFieldList. How do I correct this issue?
Example Data:
(vbCRLF is at the end of each line)
LIN~1~BP~0950-4381~EC~-~VP~-
UIT~EA
FST~0~D~D~20071 118
Code:
Set objFSO = CreateObject("S cripting.FileSy stemObject")
Set objTextFile = objFSO.OpenText File _
("Seagate.tx t", ForReading)
Do While objTextFile.AtE ndOfStream<>Tru e
strNextLine = objTextFile.Rea dline
RecDiv = Mid (strNextLine,10 6,1)
FieldDiv = Mid (strNextLine,10 4,1)
strRecList = Split(strNextLi ne , RecDiv)
redim arrFieldList(ub ound(strRecList ))
For i = 1 to ubound(strRecLi st)
wscript.echo "Write RecList: " & strRecList(i)
arrFieldList = Split(strRecLis t(i), "~")
For j = 0 to ubound(arrField List)
If arrFieldList(j) = "LIN" Then
wscript.echo "Lin Rec: Part: " & arrFieldList(j+ 3)
End If
Next
' Wscript.Echo "Service: " & arrFieldList(j)
Next
Loop
Regards,
S
My text files are delimited as follows:
Record Delimiter: vbCRLF
Field Delimiter: ~
I need to break each record apart based on the first field which defines the type of record (ex: LIN contains the part number as the 4th field ).
When I run my script I continue to get a Type Mismatch error relating to the arrFieldList. How do I correct this issue?
Example Data:
(vbCRLF is at the end of each line)
LIN~1~BP~0950-4381~EC~-~VP~-
UIT~EA
FST~0~D~D~20071 118
Code:
Set objFSO = CreateObject("S cripting.FileSy stemObject")
Set objTextFile = objFSO.OpenText File _
("Seagate.tx t", ForReading)
Do While objTextFile.AtE ndOfStream<>Tru e
strNextLine = objTextFile.Rea dline
RecDiv = Mid (strNextLine,10 6,1)
FieldDiv = Mid (strNextLine,10 4,1)
strRecList = Split(strNextLi ne , RecDiv)
redim arrFieldList(ub ound(strRecList ))
For i = 1 to ubound(strRecLi st)
wscript.echo "Write RecList: " & strRecList(i)
arrFieldList = Split(strRecLis t(i), "~")
For j = 0 to ubound(arrField List)
If arrFieldList(j) = "LIN" Then
wscript.echo "Lin Rec: Part: " & arrFieldList(j+ 3)
End If
Next
' Wscript.Echo "Service: " & arrFieldList(j)
Next
Loop
Regards,
S
Comment