I have an application that crashes when running 2 or 3 meg files. It runs for hours, crashes and starts all over again, thereby tying up the queue. I have narrowed the problem area down to a subroutine. The code follows. Any ideas area appreciated. Could my problem area be the use of Ubound???
Sub outputDocument (theHandle As Integer, theOutputDoc As NotesDocument, theColumnIdx As Integer, theDelimiter As String,theOutDocFileName As String, stream As NotesStream)
Dim i As Long
Dim j As Long
Dim k As Long
Dim delim As String
Dim s As String
Dim itm As NotesItem
On Error Goto HandleOutDocErr
If Debug > 1 Then Print "+outputDocument "
' debug msg - jrj 05/13/05
Print "theoutputdoc.lineldx(0)=" & theOutputDoc.LineIdx(0)
Print "theColumnldx" & theColumnIdx ‘ Last statement to print before crashing.
For i = 0 To theOutputDoc.LineIdx (0)
For j = 0 To theColumnIdx
Set itm = theOutputDoc.GetFirstItem ("Column" & Cstr (j+1))
k = Ubound (itm.Values)
Print "k=" & k
If i > k Then
s = itm.Values (Ubound (itm.Values))
's = itm.Values (k)
Else
s = itm.Values (i)
End If
Print "s=" & s
If j < theColumnIdx Then
delim = theDelimiter
Else
delim = Chr$ (13) & Chr$ (10)
End If
Print "delim=" & delim
’ modify with Call stream.WriteText() and Call stream.Close
Call stream.WriteText(s)
Call stream.WriteText(delim)
Next
Next
Print "before closing the stream"
Call stream.Close
If Debug > 1 Then Print "-outputDocument "
Exit Sub
HandleOutDocErr:
Print Err(), Error() & " at line " & Erl()
Resume Next
End Sub
Subject: RE: Code crashes after running for hours
“Crashes” is not an adequate description of how the code fails. I see that you inserted error trapping and other debugging output. What’s the output? You’ve identified the last line that prints, but what does it print and what happens after that? How many times have you run this to determine the failure point? Where it fails one time might not be where it fails every time.It seems possible that your process is running out of memory. Since I can’t see this routine taking long to execute, I assume you call it many times with many documents. Use the Delete statement to remove the NotesDocument from cache before processing the next document.
Ubound is a very simple function that I don’t think even needs to allocate any memory, so it’s unlikely that your use of Ubound is causing a problem.
Sounds like this is a scheduled agent? Is there a time limit on scheduled agents on this server? Could your agent have exceeded the time limit and been terminated because of that? If so, you could do some things to speed it up:
In the routine that calls this one, stop using GetNthDocument to iterate through the documents. GetNextDocument is much faster.
It takes time to read a value from a field. If you have 10 rows and 10 columns, you do 100 field reads even though there are only 10 fields. Change the algorithm to read each column field only once. For instance, you could create an array of strings with an element for each row, iterate thru the column fields, and concatenate the column’s values to the ends of the strings in your row array. After the loop, use Join to create a single string out of the array and pass that to WriteText (or loop thru the array and call WriteText for each row, but I think that will be a little slower).
Subject: RE: Code crashes after running for hours
I agree with your thought that it may be running out of memory, because we only have this problem with 2 or 3 meg files. I will try to figure out how to clear the cache for each call stream.writetext.