Return object from function

Good morning,

I got an agent containing a few functions.

  1. The “Initialize” prints a few lines to the log file, 2) Calls a function which prints a few lines to the log, 3) returns to Initilize where it once again prints.

Unfortuantly does it all take a while and the lines are printed mixed with other debug from the server… I would like to get the lines printed in one go/scope.

How can I do this? Can I return an object/array from my function containing my strings and the print it all when I reach the end of Initialize?

Or better ways to do this.

Cheers

Kjeld

Subject: Return object from function

You could use the NotesLog class:

http://www-12.lotus.com/ldd/doc/domino_notes/6.5.1/help65_designer.nsf/855dc7fcfd5fec9a85256b870069c0ab/fecc362a44eddd0285256e00004a9815?OpenDocument

This class will allow you to log your messages to a seperate database or a mail memo.

Alternatively, you could write your own class called eg Logger which would collect all the messages logged to it and then print them all out at once. You would need to either pass the Logger into all your functions or declare it as a global variable.

Your own Logger class might look something like this:

Class Logger

Private messages	List As String

Private count		As Integer



Sub new()

	Me.count = 0	

End Sub



Public Sub log( message As String )

	messages( count ) 	= message

	count 			= count + 1

End Sub



Public Sub dump()

	

	Forall message In messages

		Print( message )

	End Forall

	

End Sub

End Class

Frunobulax

Subject: RE: Return object from function

Hi Frunobulax,

Thanks for your answer. I have added the class to the declaration scope and tried this in the Initialize,

Dim myLogger As Logger

myLogger.log("TTT Test")

myLogger.dump

Is that correct?

Thanks,

Kjeld

Subject: RE: Return object from function

Yep,

the dump() method will print() all the messages which have been logged.

Frunobulax

Subject: RE: Return object from function

Hi,

the thing is that nothing happens when I use it like this. No lines are printing.

I thought that I had to use () when using dump() but I get an error “Illegal use of parantheses”.

Any ideas?

Subject: RE: Return object from function

My test looked something like this:

Set logger		= New Logger()



Call logger.log("Message 1")

Call logger.log("Message 2")	

Call logger.log("Message 3")



Call logger.dump()

Frunobulax

Subject: RE: Return object from function

Hi,

Have to continue asking questions… :slight_smile:

When I declare my object in Initialize, can I use the functions log() and dump(). I cant do this from a different function.

How can I make my logger object global and how can I call it from a sub function?

Thanks,

Kjeld

Subject: RE: Return object from function

Put the declaration of the object in the Declarations section:

dim logger as Logger

Instantiate the object in the Initialize section:

set logger = new Logger()

Frunobulax

Subject: RE: Return object from function

Perfect!

Thanks for your great help.

Kjeld

Subject: RE: Return object from function

Thanks,

Got it working now.

Kjeld