Re-spliting a split - Type Mismatch

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seanf67
    New Member
    • Dec 2007
    • 2

    #1

    Re-spliting a split - Type Mismatch

    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
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by seanf67
    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~f our
    five~six~seven~ eight
    nine~ten~eleven ~twelve

    I will use an split for Chr(10) and then the Split for "~"
    [CODE=vb]Dim i As Integer
    Dim Arr1() As String
    Dim Arr2()
    Arr1 = Split(str1, Chr(10))
    For i = LBound(Arr1) To UBound(Arr1)
    ReDim Preserve Arr2(0 To i)
    Arr2(i) = Split(Arr1(i), "~")
    Next[/CODE]

    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

    Comment

    • seanf67
      New Member
      • Dec 2007
      • 2

      #3
      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




      Originally posted by kadghar
      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~f our
      five~six~seven~ eight
      nine~ten~eleven ~twelve

      I will use an split for Chr(10) and then the Split for "~"
      [CODE=vb]Dim i As Integer
      Dim Arr1() As String
      Dim Arr2()
      Arr1 = Split(str1, Chr(10))
      For i = LBound(Arr1) To UBound(Arr1)
      ReDim Preserve Arr2(0 To i)
      Arr2(i) = Split(Arr1(i), "~")
      Next[/CODE]

      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

      Comment

      Working...