1
votes

I am trying to create a text file in lotus notes which I am running through the agents. The agent ran successfully but the text file is not created in the path which is specified in the lotus script.

This is the lotus script code:

Option Public
Sub Initialize  
    MsgBox " Agent AccessUserList"
    On Error GoTo HandleError   
    Dim session As New NotesSession
    Dim myStream As NotesStream
    Dim TheDate As String, filename As String 
    TheDate=Format(Now(),"mmdd")    
    filename = "C:"+"\red"+"\color"+TheDate+".txt"
    MsgBox filename
    Set myStream = session.Createstream()
    MsgBox "MySTREAM2"
    Call myStream.Open(filename, "ASCII")
    MsgBox "MySTREAM3"
    Call myStream.Truncate()
    MsgBox "Entered View"

closeFile:
    Call myStream.Close()
    MsgBox "Closed"
    Exit Sub
HandleError:     
    MsgBox "Error  - " & Error &" at line number  " & Erl
    Exit Sub    
End Sub

I have scheduled to 5 min to check whether it creates a new file in specified folder

enter image description here

And also the privileges while scheduling I used both second and third Allow restricted operations Allow Restricted operations with full administrator rights

But still it shows the folder as empty but the folder time would be changed when this it gets scheduled.

To test it i scheduled the agent to run locally as well as in the server. But the error is same the text file is not created.

Agent log is not having any errors.

enter image description here

I have checked in the logs as well and there is no errors. Can anyone tell what is the mistake in the above code and why my file is not getting created when the agent executes correctly.

2
Do u find any issue in this code @Kurt Van den BrandenLotusWorst
@Torsten Link Can you let me know error in this codeLotusWorst
I just want to check on something: Do you expect the file to be "colorMMDD.txt" in folder C:\red? Or do you expect the file to be MMDD.txt in folder c:\red\color? You've got it coded the first way.Richard Schwartz

2 Answers

1
votes

NotesStream doesn't work for you as you just want to create an empty file.
Call myStream.Close() always deletes just now created file if it's empty at this point.

Use traditional FreeFile()/Open/Close instead:

Sub Initialize
    On Error GoTo HandleError   
    Dim TheDate As String
    Dim filename As String 
    Dim fileNum As Integer

    TheDate = Format(Now(),"mmdd")    
    filename = "C:\red\color" + TheDate + ".txt"
    fileNum = FreeFile
    Open filename For Output As fileNum
    Close fileNum

Finally:
    Exit Sub

HandleError:     
    MsgBox "Error  - " & Error &" at line number  " & Erl
    Resume Finally    
End Sub
0
votes

When a stream is truncated, property values are: • Bytes is 0 • IsEOS is True • Position is 0

Closing a stream with zero bytes deletes the associated file.

Your file is getting created and then deleted because it's empty.