Function's return value is lost outside script library

Here is a very strange situation; I do not recall ever seeing this behaviour with LotusScript in any version prior to ND6.Basically, A given function will return a proper object handle when used inside the same lotusScript library, but that handle will be lost when the function is called from outside the library. (for instance, when called from a view action script , through a Use Library statement)

Here are the gory details:

INSIDE a script library, we have a FUNCTION which is set to return a handle to a NotesDocument:

Function GetSecurityProfile (CompanyCode As String) As NotesDocument

   '..... several lines of code snipped



   Set GetSecurityProfile =  .....   'proper final assignment in order to return the correct handles

End Function

This function works perfectly, and the debugger confirms that the proper document handle is returned.

Now, let’s call this function from a view action:

(Options)

Use “SecurityAccounts”

Click

Sub Click(Source As Button)

            Dim wk as New NotesUIWorkspace

            Dim doc As NotesDocument



Set doc = GetSecurityProfile (CustomerKey)  'assumes CustomerKey is correctly assigned

If doc Is Nothing Then

	Messagebox "Error: " & CustomerKey & " not found!"

	Exit Sub

End If

Call wk.editDocument (False, doc)

End Sub

The debugger confirms that, WHILE INSIDE the GetSecurityProfile function, the proper handle is returned.

But once we leave the function and return to the calling script, the handle is set to Nothing.

Of course, I can force the full function to be a STATIC function, and then it works, but that’s quite messy and in addition, It seems I never had this kind of behaviour in the past version.

Can someone advise?

Thank you

Nicolas Abesdris

Subject: Function’s return value is lost outside script library

You’re probably declaring and setting the value of the NotesDocument’s parent database inside the function, which is outside the scope of the calling function. As a result, although you return the right document, the containing database is no longer open.

You can either pass the database and the document and pass them both back, or you can declare the database globally.

Subject: RE: Function’s return value is lost outside script library

This sounds right to me. Its all to do with scope - I think its been brought up several times in this forum

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/5ee34b40c66bcba585256cd1007f51e1?OpenDocument&Highlight=0,scope