Form Scope help

I don’t want to keep declaring a new s as New NotesSession and db.CurrentDatabase, etc. So I have them declared in a library, which is being used in the form’s Globals (Options) area.

Did I do that right? What is the best way to include all these universal variables and not have to pass them around as parameters?

Also note that right now, I am getting the “Duplicate PUBLIC name in use…” message that you get when you do this kind of thing wrong.

Thanks.

-Jeff

Subject: Form Scope help

I would only declare variables in the Globals area if I intend to use them in form events as well as action buttons, hotspots, etc. Even then, I think there were issues with calling a script library in Globals. Under a previous version (not sure about current), I believe that Designer actually copied the Object code into each and every design element when saving the form, resulting in large file sizes.

If you need to declare them only for the form events, then do so at the Form’s Declarations section and not the Global declarations section.

Subject: RE: Form Scope help

What about when I want to include them for form events, fields, and in USE libraries?

Subject: RE: Form Scope help

Again, declare variables within the smallest scope that makes sense in your application.

By the way, the error you are receiving is because you declared a global variable in the form having the same name as another variable declared in the Global section of a script library.

Subject: RE: Form Scope help

I cannot find any other variables in the script libraries declared with the same name.

OK, some hopefully simple questions (of course, this seems like it shoudl be a simple subject, but it’s not working the way I expect).

Are the form’s Globals’ Declarations considered Module scope, Procedure scope, or Type/Class scope?

The form has another Declarations section, which is hanging off the “formname (Form)” tree. Is that Module, Procedure, or Type/Class scope?

What scope is the script library’s Options and Declarations?

If it’s declared in the Globals’ declarations, and initialized in the Globals’ Initialize statement, would it be available to everything on the form? How about the script libraries?

The library’s Use statement is in the form’s Globals section, so shouldn’t any declarations made in the library’s Declarations be equivalent to the form’s Globals section?

Possibly more to come.

Thanks for your help Cesar!

-Jeff

Subject: RE: Form Scope help

It could be that one script library “uses” another and this duplicate variable is actually declared in one of the script libraries in the chain.

As for your other questions, I suspect you have read the designer help topic titled “Scope of Declarations” but sometimes it’s better to understand how those declarations work rather than interpreting the definitions.

The form has another Declarations section, which is hanging off the “formname (Form)” tree.

Variables declared in the Globals declaration section of the form are visible to ANY LotusScript code within the form, be that form events, fields, hotspots, actions, etc. Those declared in the Declarations section “hanging off the Form tree” are visible only to Form events, not fields, or hotspots, etc.

What scope is the script library’s Options and Declarations? If it’s declared in the Globals’ declarations, and initialized in the Globals’ Initialize statement, would it be available to everything on the form?

The Script Library declarations section will declare variables visible to all other code that “uses” that script library, unless the variable is marked as Private. Public variables (or those with undeclared scope) can be set in the Script Library’s Initialize and have that value visible to all other script using the script library.

The library’s Use statement is in the form’s Globals section, so shouldn’t any declarations made in the library’s Declarations be equivalent to the form’s Globals section?

Yes. But while a script library can be used within other script elements, a form’s Globally declared variables cannot. So, sometimes you declare global variables in script because those will be used by code that runs in forms, subforms, agents, etc.

And now I have to run - it is the end of my day. Hope that helps.

Subject: RE: Form Scope help

Thanks Cesar. It helps some. I’m getting there.-Jeff

Subject: RE: Form Scope help

Here’s my scenario that’s not working.

Form Status includes library slANCustomized which, in turn, includes library slANAutoNumbering. The last library listed has the following Declarations and Initialize:

Public w As NotesUIWorkspace

Public s As NotesSession

Public db As NotesDatabase

Sub Initialize

Set w = New NotesUIWorkspace

Set s = New NotesSession

Set db = s.CurrentDatabase

End Sub

Form Status’ QuerySave has the following lines:

Dim resourcedb As notesdatabase

Set resourcedb = New notesdatabase(db.Server, tmp(0))

Where tmp(0) is set to “WIP\WIPresource.nsf”. But I get an error saying “Object variable is not set”. Why am I getting this error?

Also, how come the library’s Initialize routine doesn’t execute in the debugger?

Subject: RE: Form Scope help

OK, nevermind this specific question. I had an extraneous

Public db As NotesDatabase

in the Querysave.

But still curious why the library’s Initialize doesn’t work in the Debugger.