Passing parameters to from Sub

I in LS hotspot I use subs that are in same LSLibrary. Parameters are decraled the same way for both subs.

GetApplicationDatabase(fieldname as string, targetdb as NotesDatabase, targetDbPath as String)

and second is like

GetCreditDoc(creditDoc as NotesDocument, BalanceDoc as NotesDocument)

The problem is that before exiting subs I have parameters set to what I need, but when I get back in code that calls these functions credtiDoc and BalanceDoc is nothing while targetDb and targetDbPath are OK.

First is called GetApplicationDatabase and then getCreditDoc. CreditDoc uses itself GetApplicationDatabase with differend params.

The result is the same even if I put the subs in the form.

Any sugestions?

Subject: Passing parameters to from Sub

You need to convert your subs to functions. For example, instead of:

Sub GetCreditDoc()

you should have

Function GetCreditDoc() as whatever

Then instead of just calling the sub, do something like:

x = GetCreditDoc(xxx,xxx,xxx,xxx)

(with the “xxx”'s being the values passed to the function)

This will return to x in the calling script whatever the function results in.

See if that helps.

  • Matt

Subject: RE: Passing parameters to from Sub

I thought of that, but it is time consuming as for example to get creditDoc and to get balanceDoc I need to call getApplicationDatabase.

And I have several cases like this and I am afraid not to become slow.

Just wandering. 10x.

Subject: Passing parameters to from Sub

Elka,

You have a problem of ‘scope’.

I assume that in the subs you are doing some combination of .getDatabase(…) and .getDocumentByKey(…) etc.

The problem is that a NotesDocument is only valid as long as the NotesDatabase is still in scope. When you exit the subs your NotesDatabase is going out of scope and the associated NotesDocuments are no onger valid.

Frunobulax

Subject: RE: Passing parameters to from Sub

Thanx a lot. That was the case.I decided to declare global variables and left that Subs in the form. Although i am not happy with the situation when I have enough time I put some work on optimizing the code.