Hi
Apologies, this is a bit of a Hail Mary. Just putting it out there.
I am having difficulty with a function where after completing 2 nested "for each" loops it just ends without completing the final operations. I can see no reason why. It used to work, not sure why it does not now. The function code parses the audit log of trouble tickets and is called once for each ticket. The full code goes through many tickets - all with the same result. The function aborts or escapes at the second NEXT statement so that the line with the "+++++"s is not displayed and the passed array is not updated.
Any thoughts would be appreciated.
Code overview:
FUNCTION Parse(aRecords)
sRecords = split(aRecords,";")
FOR EACH sRecord in sRecords
sLine = split(sRecord,chr(10))
FOR EACH sLine in aRecords
<< parsing code >>
NEXT
NEXT
<<Problem occurs here, code that is not executed >>
END FUNCTION
Actual code is here.
Function ParseLog(ByRef arrRecordArray, ByRef X, ByRef nColAuditLog)
strRecord = ""
boolAccepted = False
IF (DEBUGMODE>1) then wscript.echo vbcrlf & "Starting new ticket:" & vbcrlf END IF
sTemp = arrRecordArray(nColAuditLog,X)
aryLogEntries = split(sTemp,"")
arrayLength = UBound(aryLogEntries,1)
IF (DEBUGMODE>1) then wscript.echo "Array Length: " & arrayLength & vbcrlf END IF
nAK = right("0"&arrayLength,2)
k = 0
FOR EACH strLogEntry IN aryLogEntries
k = k + 1
nEK = right("0"&k,2)
IF (DEBUGMODE>1) then wscript.echo "[" & nEK & "/" & nAK & "]" END IF
aryLogEntryElements = split(strLogEntry,"")
strEpoch = aryLogEntryElements(0)
strTimeStamp = DateAdd("s", strEpoch, "01/01/1970 00:00:00")
strStaff = aryLogEntryElements(1)
aryCommentLines = aryLogEntryElements(2)
aryCommentLines = RxReplace(aryCommentLines,chr(13),chr(10))
aryLines = split(aryCommentLines,chr(10))
numLines = UBound(aryLines)
nAL = right("0"&numLines+1,2)
l = 0
FOR EACH strLine IN aryLines
l = l+1
strRecTemp = ""
nEL = right("0"&l,2)
IF (INSTR(strLine,"Submitted in the") > 0 ) THEN
dateCreate = strTimeStamp
IF instr(strLine,"Accept") > 0 THEN
IF NOT (boolAccepted) THEN
dateAccepted = strTimeStamp
boolAccepted = TRUE
END IF
END IF
if instr(strLine,"Resolved") > 0 then strStatus="resolved"
strPending = strPending & "[Submit=Resolved]" & vbcrlf
dateResolved = strTimeStamp
dateAccepted = strTimeStamp
HoldStart = strEpoch
numTechs = numTechs + 1
elseif (instr(strLine,"Accept Assignment") > 0) then
strStatus = "working"
strPending = strPending & "[Submit=Accept Assignment]" & vbcrlf
WorkStart = strEpoch
numTechs = numTechs + 1
elseif (instr(strLine,"Accept Ownership") > 0) then
strStatus = "working"
strPending = strPending & "[Submit=Accept Ownership]" & vbcrlf
WorkStart = strEpoch
numTechs = numTechs + 1
elseif (instr(strLine,"Work") > 0) then
strStatus = "working"
strPending = strPending & "[Submit=Work in Progress]" & vbcrlf
dateAccepted = strTimeStamp
WorkStart = strEpoch
numTechs = numTechs + 1
elseif instr(strLine,"Open") > 0 then
strStatus = "holding"
strPending = strPending & "[Submit=Open]" & vbcrlf
HoldStart = strEpoch
elseif instr(strLine,"Assigned") > 0 then
strStatus = "holding"
strPending = strPending & "[Submit=Assigned]" & vbcrlf
HoldStart = strEpoch
elseif instr(strLine,"Pending") > 0 then
strStatus = "holding"
strPending = strPending & "[Submit=Pending]" & vbcrlf
HoldStart = strEpoch
else
strStatus = "holding"
strPending = strPending & "[Submit=not defined]" & vbcrlf
HoldStart = strEpoch
End if
IF INSTR(strLine,":") > 0 THEN strLine = cleanString(strLine) END IF
strRecTemp = "[" & strTimeStamp & "][" & strLine & "]" & chr(10)
IF (DEBUGMODE>2) then wscript.echo "[" & nEK & "/" & nAK & "][" & nEL & "/" & nAL & "][KEEP]" & strRecTemp END IF
ELSEIF instr(strLine,"Status Changed from") > 0 OR instr(strLine,"NOTIFIED OF") > 0 then
numStatusChange = numStatusChange + 1
IF instr(strLine,"to Accept") > 0 THEN numTechs = numTechs + 1 END IF
IF instr(strLine,"Accept") > 0 THEN
IF NOT (boolAccepted) THEN
dateAccepted = strTimeStamp
boolAccepted = TRUE
END IF
END IF
SELECT CASE strStatus
Case "resolved"
if instr(strLine,"to Accept") > 0 OR instr(strLine,"to Work In Progress") > 0 OR _
InStr(strLine,"NOTIFIED OF RESOLUTION") > 0 THEN
strStatus="working"
WorkStart = strEpoch
HoldStop = strEpoch
HoldTime0 = HoldStop - HoldStart
HoldTime = HoldTime + HoldTime0
strPending = strPending & "[resolved->working(hold:" & HoldTime0 & ")]" & vbcrlf
HoldTime0 = "0"
else
strStatus="holding"
strPending = strPending & "[reopened on hold]"
end if
Case "working"
if instr(strLine,"to Resolved") > 0 OR instr(strLine,"NOTIFIED OF RESOLUTION") THEN
strStatus="resolved"
dateResolved = strTimeStamp
WorkStop = strEpoch
HoldStart = strEpoch
WorkTime0 = WorkStop - WorkStart
WorkTime = WorkTime + WorkTime0
strPending = strPending & "[work->resolved(work:" & WorkTime0 & ")]" & vbcrlf
WorkTime0 = "0"
else
strStatus="holding"
HoldStart = strEpoch
WorkStop = strEpoch
WorkTime0 = WorkStop - WorKStart
WorkTime = WorkTime + WorkTime0
strPending = strPending & "[working->hold(work:" & WorkTime0 & ")]" & vbcrlf
WorkTime0 = "0"
end if
Case "holding"
if instr(strLine,"to Accept") > 0 OR instr(strLine,"to Work In Progress") > 0 then
strStatus="working"
dateAccepted = strTimeStamp
WorkStart = strEpoch
HoldStop = strEpoch
HoldTime0 = HoldStop - HoldStart
HoldTime = HoldTime + HoldTime0
strPending = strPending & "[open->working(hold:" & HoldTime0 & ")]" & vbcrlf
HoldTime0 = "0"
elseif instr(strLine,"to Resolved") > 0 OR instr(strLine,"NOTIFIED OF RESOLUTION") > 0 then
strStatus="resolved"
dateResolved = strTimeStamp
HoldStop = strEpoch
HoldStart = strEpoch
HoldTime0 = HoldStop - HoldStart
HoldTime = HoldTime + HoldTime0
strPending = strPending & "[open->resolved(hold:" & HoldTime0 & ")]" & vbcrlf
HoldTime0 = "0"
else
strStatus="hold"
end if
Case else
' 'status was not defined
End Select
IF INSTR(strLine,":") > 0 THEN strLine = cleanString(strLine) END IF
strRecTemp = "[" & strTimeStamp & "][" & strLine & "]" & chr(10)
IF (DEBUGMODE>2) then wscript.echo "[" & nEK & "/" & nAK & "][" & nEL & "/" & nAL & "][KEEP]" & strRecTemp END IF
ElseIf instr(strLine,"Ticket removed as child from Global Incident") > 0 then
wscript.echo "[" & nEK & "/" & nAK & "][" & nEL & "/" & nAL & "][....][CHILD: " & strLine & "]"
ELSE
IF len(strLine) = 0 THEN strLine = "<< blank line >>" END IF
IF (DEBUGMODE>2) then
wscript.echo "[" & nEK & "/" & nAK & "][" & nEL & "/" & nAL & "][....][unhandled line: " & strLine & "]"
END IF
END IF ' ' IF (INSTR(strLine,"Submitted in the") > 0 ) THEN
strRecord = strRecord & strRecTemp ' ' IF (DEBUGMODE>1) then wscript.echo "[TMPREC]" & strRecTemp END IF
NEXT ' ' FOR EACH strLine IN aryLines
Wscript.Echo "**************************************************************************************" & vbcrlf
IF (DEBUGMODE>1) then wscript.echo "[RECORD]" & strRecord END IF
NEXT ' ' FOR EACH strLogEntry IN aryLogEntries
Wscript.Echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
IF (DEBUGMODE>1) then wscript.echo "[FINAL RECORD]" & strRecord END IF respTime = DateDiff("n",dateCreate,dateAccepted)
' ' resvTime = DateDiff("n",dateAccepted,dateResolved)
resvTime = DateDiff("n",dateCreate,dateResolved)
strRecord = RxReplace(strRecord,"","")
strRecord = RxReplace(strRecord,","," ")
strRecord = RxReplace(strRecord,chr(34),"'")
strRecord = Chr(34) & strRecord & Chr(34)
strRecord = RxReplace(strRecord," Status","")
strRecord = RxReplace(strRecord,"False","")
strRecord = RxReplace(strRecord,"Incident was Submitted in the ","Submitted as: ")
strRecord = RxReplace(strRecord,"Status Changed from ","")
strRecord = RxReplace(strRecord," to ","->")
arrRecordArray(nColAuditLog,X) = respTime
arrRecordArray(nColAuditLog+1,X) = resvTime
arrRecordArray(nColAuditLog+2,X) = WorkTime
arrRecordArray(nColAuditLog+3,X) = HoldTime
arrRecordArray(nColAuditLog+4,X) = numStatusChange
arrRecordArray(nColAuditLog+5,X) = numTechs
arrRecordArray(nColAuditLog+6,X) = strPending
arrRecordArray(nColAuditLog+7,X) = strRecord IF (DEBUGMODE>1) then
wscript.echo "[Resolve Time][" & resvTime & "]" & vbcrlf
wscript.echo "[Response Time][" & respTime & "]" & vbcrlf
wscript.echo "[Work Time][" & WorkTime & "]" & vbcrlf
wscript.echo "[Hold Time][" & HoldTime & "]" & vbcrlf
wscript.echo "[Status Changes][" & numStatusChange & "]" & vbcrlf
wscript.echo "[Num Technicians][" & numTechs & "]" & vbcrlf
END IF strRecord = ""
strPending = "" End Function
<message edited by cgmoller on Wednesday, November 16, 2011 8:20 PM>