By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,646 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,646 IT Pros & Developers. It's quick & easy.

Re-spliting a split - Type Mismatch

P: 2
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~20071118



Code:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("Seagate.txt", ForReading)

Do While objTextFile.AtEndOfStream<>True
strNextLine = objTextFile.Readline
RecDiv = Mid (strNextLine,106,1)
FieldDiv = Mid (strNextLine,104,1)
strRecList = Split(strNextLine , RecDiv)

redim arrFieldList(ubound(strRecList))
For i = 1 to ubound(strRecList)
wscript.echo "Write RecList: " & strRecList(i)
arrFieldList = Split(strRecList(i), "~")

For j = 0 to ubound(arrFieldList)
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
Dec 6 '07 #1
Share this Question
Share on Google+
2 Replies


kadghar
Expert 100+
P: 1,295
vbscript: Spilt Issue

My text files are delimited as follows:
Record Delimiter: vbCRLF
Field Delimiter: ~
...

S
vbCRLF is chr(10) & chr(13) that are for next line and car return. you can only search for one of them as the Line Delimiter

lets say your Str1 is
one~two~three~four
five~six~seven~eight
nine~ten~eleven~twelve

I will use an split for Chr(10) and then the Split for "~"
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim Arr1() As String
  3. Dim Arr2()
  4. Arr1 = Split(str1, Chr(10))
  5. For i = LBound(Arr1) To UBound(Arr1)
  6.     ReDim Preserve Arr2(0 To i)
  7.     Arr2(i) = Split(Arr1(i), "~")
  8. Next
As you can see, this code give you Arr2 as the matrix we needed, but depending on the version of VB it'll have to be a Variant and it'll be a jagged array.

Jagged array is an array of arrays, so instead of have Arr2(i,j) you'll have Arr2(i)(j).

HTH
Dec 6 '07 #2

P: 2
HTH,

Thank you for the response.
I actually need to add an additional detail: My code is for a WSF so I cannot define variables to the nth degree.

Still working to resplit my split.

S




vbCRLF is chr(10) & chr(13) that are for next line and car return. you can only search for one of them as the Line Delimiter

lets say your Str1 is
one~two~three~four
five~six~seven~eight
nine~ten~eleven~twelve

I will use an split for Chr(10) and then the Split for "~"
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim Arr1() As String
  3. Dim Arr2()
  4. Arr1 = Split(str1, Chr(10))
  5. For i = LBound(Arr1) To UBound(Arr1)
  6.     ReDim Preserve Arr2(0 To i)
  7.     Arr2(i) = Split(Arr1(i), "~")
  8. Next
As you can see, this code give you Arr2 as the matrix we needed, but depending on the version of VB it'll have to be a Variant and it'll be a jagged array.

Jagged array is an array of arrays, so instead of have Arr2(i,j) you'll have Arr2(i)(j).

HTH
Dec 10 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.