Type mismatch on splitting string with vbscript

I’m banging my head against a wall here. I am using PlanetPress Connect and have this vbscript in my workflow. I keep getting type mismatch errors when i try to split txtLine on a pipe and I have no clue why. When I log txtLine I see the correct string in the log but for some reason I’m getting this error. Any idea whats going wrong?

'Michal Wycklendt

' Preprocess input data, check for /

Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim ObjFSO, Content, documentArray, OurFile, linesArray
Dim LineCount, DiffLines, vOut, iOut, cOut, theError, ret
Dim xDataPath, inputPath, outputDataPath, document, docLinesCount
Dim stabilizedDocument, stabilizedDocumentsArray,valid, invalid, memberID
Dim excFilePath, cleanDoc, dateLine, noFirst, firstLine, pdfName, regEx, Page
Dim dbArray, dbRead, dbFile, dbResultsPath, xErrorThisFile, addressCount
Dim addressPath, addressArray, addressFile, addressRead, addressesArray, addressLine
Dim errorLogFile, errorLogPath, errorLogArray, errorsArray, newErrors, errorsRead, errorLine
Dim xError, errorMessage, fileName, toCheck, pdfLines, pageNum, badLine, lineNo, fulladdress
Dim i, pdfDocuments, errorMessageForLog, split, fileMemberID, dbMemberID, line, csz, street
Dim dbFieldArray, secondLine, thirdLine, fourthLine, txtAddress, errorsToAdd, errorsToWrite
Dim addressFSO, errorLogFSO, addressContent, errorsContent 
Dim newAddressArray
Dim txtLine

Set objFSO = CreateObject("Scripting.FileSystemObject") 'creating a "file system" object
Set valid = CreateObject("System.Collections.ArrayList")
Set invalid = CreateObject("System.Collections.ArrayList")
Set errorsArray = CreateObject("System.Collections.ArrayList")
Set pdfDocuments = CreateObject("System.Collections.ArrayList")
Set dbFieldArray = CreateObject("System.Collections.ArrayList")
Set addressesArray = CreateObject("System.Collections.ArrayList")
Set errorLogArray = CreateObject("System.Collections.ArrayList")
Set addressFSO = CreateObject("Scripting.FileSystemObject")
Set errorLogFSO = CreateObject("Scripting.FileSystemObject")

xDataPath = Watch.getVariable("xBaseDataPath")
xError = Watch.getVariable("xError")
xErrorThisFile = Watch.getVariable("xErrorThisFile")
fileName = Watch.getVariable("theFileName")
Dim xBaseAppPath: xBaseAppPath = Watch.GetVariable("xBaseAppPath")
Dim xJob: xJob = Watch.GetVariable("xJob")
fileMemberID = Watch.GetVariable("fileMemberID")
memberID = Watch.GetVariable("Member_ID")


excFilePath = xDataPath & "\FilesTemp\Exeption.txt"
errorLogPath = xDataPath & "\FilesTemp\errorLog.txt"
addressPath =  xDataPath & "\FilesTemp\Address.txt"


Set addressRead = addressFSO.OpenTextFile(addressPath, ForReading)
Set errorsRead = errorLogFSO.OpenTextFile(errorLogPath, ForReading)

   '     addressContent = addressRead.ReadAll
  '      addressContent = CStr(addressContent)
 '       errorsContent = errorsRead.ReadAll
'        errorsContent = CStr(errorsContent)



    
    ' split file based on FF characters
'newAddressArray = Split(addressContent, chr(13) & chr(10))
'errorLogArray = Split(errorsContent, chr(13) & chr(10))
'newaAdressArray = Split(addressContent, vbCRLF)
'errorLogArray = Split(errorsContent, vbCRLF)

Do Until addressRead.AtEndOfStream
    addressLine = addressRead.ReadLine
    addressesArray.Add addressLine
Loop

Do Until errorsRead.AtEndOfStream
    errorLine = errorsRead.ReadLine
    errorLogArray.Add errorLine
Loop

addressRead.Close

i = 0

    ' loop based on documents
    For Each document In addressesArray
            txtLine = CStr(document)
            Watch.Log txtLine, 2
            address = Split(txtLine, "|")
             page = address(0)
             firstLine = address(2)
             secondLine = address(3)
             thirdLine = address(4)
             fouthLine = address(5)
             csz = thirdLine & fourthLine
             street = secondLine
             txtAddress = Array(firstLine, secondLine, thirdLine, fouthLine)
             fullAddress = firstLine & secondLine & thirdLine & fourthLine 

             i = i + 1

             Set regExp = New RegExp
             regExp.IgnoreCase = True
             regExp.Global = True
             regExp.Pattern = "[^!?@|\/$%*~`+=;<>{}]" 'Add here every character you don't consider as special character

             lineNo = 0


            For Each line In txtAddress
                lineNo = lineNo + 1
                badLine = regExp.Replace(line, "<BadChar>")
            
                If InStr(1, badLine, "<BadChar>") Then 
                    xError = "true"
                    xErrorThisFile = "true"
                    errorMessage = "Special character in address."
                    PBMonitor errorMessage, "yellow", xBaseAppPath, xJob
                    errorMessageForLog = "There is a special character in line " & lineNo & " in the address on page " & i & " of the document."
                    errorsArray.Add errorMessageForLog 
                End If
            Next    


            if isDate(firstline) Then
                xError = "true"
                xErrorThisFile = "true"
                errorMessage = "First Line of Address is date."
                PBMonitor errorMessage, "yellow", xBaseAppPath, xJob
                errorMessageForLog = "The first line of the address on page " & i & " is a date."
                errorsArray.Add errorMessageForLog 
            End If

            If firstLine = "" Then
                xError = "true"
                xErrorThisFile = "true"
                errorMessage = "No first line of address"
                PBMonitor errorMessage, "yellow", xBaseAppPath, xJob
                errorMessageForLog = "The Address on page " & i & " does not have a first line of the address."
                errorsArray.Add errorMessageForLog
            End If

            If Not InStr(1, csz, ",") Then
                xError = "true"
                xErrorThisFile = "true"
                errorMessage = "No City, State Zip"
                PBMonitor errorMessage, "yellow", xBaseAppPath, xJob
                errorMessageForLog = "The address on page " & i & " does not have a city, state zip."
                errorsArray.Add errorMessageForLog
            End If

            addressCount = 0

            For Each line in txtAddress
                If line <> "" Then
                    addressCount = addressCount + 1
                End If
            Next

            If addressCount < 3 Then
                xError = "true"
                xErrorThisFile = "true"
                errorMessage = "Missing address element"
                PBMonitor errorMessage, "yellow", xBaseAppPath, xJob
                errorMessage = "The address on page " & i & " has a missing element."
            End If
    Next

    if Not InStr(2, fileName, ".pdf") Then
        xError = "true"
        xErrorThisFile = "true"
        errorMessage = "No pdf extension"
        PBMonitor errorMessage, "yellow", xBaseAppPath, xJob
        errorMessageForLog = "The file " & fileName & " does not have a pdf extension."
        errorsArray.Add errorMessageForLog
    End If

    If memberID = "none" Then
        xError = "true"
        xErrorThisFile = "true"
        errorMessage = "No Matching Member ID"
        PBMonitor errorMessage, "yellow", xBaseAppPath, xJob
        errorMessageForLog = "The Member ID " & fileMemberID & " does not have a match in the database."
        errorsArray.Add errorMessageForLog
    End If

    errorLogArray.Add vbCRLF
    errorLogArray.Add vbCRLF
    errorLogArray.Add fileName
    errorLogArray.Add vbCRLF

    For Each theError In errorLogArray
        errorsRead.WriteLine theError
    Next 


Set vOut = objFSO.OpenTextFile(errorLogFile, ForWriting, True)

vOut.write errorsRead

vOut.Close

Watch.setVariable "xError", xError
Watch.setVariable "xErrorThisFile", xErrorThisFile
' End Script

' Update Framework Variables

' Clean Up Objects

Set OurFile = Nothing
Set vOut = Nothing
Set iOut = Nothing
Set objFSO = Nothing


' Test Script
' James A. Webb
' Pitney Bowes - ATG


Dim X


X = 0

If X = 0 then
   rtn = PBMonitor("A Bad File Was Found", "yellow", xbaseAppPath, xJob)
'   Err.Raise 12345, "Test Script", "An error was Received"
End If


Function PBMonitor(Message, Icon, BaseAppPath, Job)

Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2

Dim fso, myFile
Dim MyProcess
Dim MyStatus
Dim MyIcon
Dim MyRecord
Dim MyMessage
Dim NextCount, HoldErr

Dim MyDate
Dim MyHour, MyMinute, MySecond, MyTemp

' 000JAW    Add NOMON Switch to Skip Monitor Posts
Dim xDashType
xDashType = Watch.GetVariable("global.xDashType")

If xDashType = "NOMON" Then Exit Function
' 000JAW

MyMessage = Message
MyIcon = LCase(Icon)
Select Case MyIcon
Case "blue"
  MyStatus = "information_32.png"
Case "red"
  MyStatus = "error_32.png"
Case "green"
  MyStatus = "checkmark_32.png"
Case "yellow"
  MyStatus = "warning_32.png"
Case Else
  MyStatus = "information_32.png"
End Select

Set fso = CreateObject("Scripting.FileSystemObject")

MyDate = Now()
MyHour = Right(Hour(MyDate) + 100, 2)
MyMinute = Right(Minute(MyDate) + 100, 2)
MySecond = Right(Second(MyDate) + 100, 2)


MyRecord = ",[" & Chr(34) & "<img src='/htmlFiles/StatusIcons/" & MyStatus & "' />" & Chr(34) & "," & _
  Chr(34) & Job & Chr(34) & "," & _
  Chr(34) & Date & " " & Time & Chr(34) & "," & _
  Chr(34) & MyMessage & Chr(34) & "," & _
  Chr(34) & DateDiff("d", "01/01/2000 00:00:00", MyDate) & MyHour & MyMinute & MySecond & Chr(34) & "]"

NextCount = 0
On Error Resume Next

Set myFile = fso.OpenTextFile(BaseAppPath & "\Dashboard\log.txt", ForAppending, True)
Do Until Err <> 70 Or NextCount > 120
  myFile.Close
  Set myFile = Nothing
  Set myFile = fso.OpenTextFile(BaseAppPath & "\Dashboard\log.txt", ForAppending, True)
  NextCount = NextCount + 1
  Watch.sleep (500)
Loop

HoldErr = Err
On Error GoTo 0
If HoldErr = 70 Then Err.Raise 70
myFile.WriteLine MyRecord
myFile.Close
Watch.sleep (1000)
Set myFile = Nothing
Set fso = Nothing

PBMonitor = true

End Function

What error are you getting? On which line? Can you share a data sample with which to replicate the issue?

xError = false
xErrorThisFile = false
fileName = file.txt
x
xBaseAppPath: = unnecessary → comment out all uses of PBMonitor Function
xJob = unnecessary → comment out all uses of PBMonitor Function
fileMemberID = 4321
memberID = 1234
xDataPath = unnecsessary → comment out
errorLogPath = path to errorLog.txt
addressPath = path to Address.txt

Address.txt contents:
10000001|2|CECELIA LAWHORN|1057 FINNEY DRIVE|VINTON, VA 24179-2923||||||||||||||||

errorLog.txt contents:
Error Log

I think thats everything

Looks like those error messages could be stored as default values in your local variables named xBaseAppPath, xJob and xDataPath. I have no idea what they mean, though.

Have you tried contacting PB, who obviously wrote this script originally?