Are forms declared publicly and/or can you declare a public sub in a form?

Hey all,

If I create a new form and call it form1, can I then add a sub to that form called mySub and make a call to that form like this?

form1.mysub()

My thought here is that I want to re-use some of the existing functions I have in my form in other objects on the form (specifically in this case I want to use that sub in an action)

So if I dim a local variable like this:

dim thisForm as NotesForm

then use it like this:

thisForm.MySub()

Is that legal?

Shawn

Subject: Are forms declared publicly and/or can you declare a public sub in a form?

No. Move your functions into script libraries, preferably into classes.

Subject: RE: Are forms declared publicly and/or can you declare a public sub in a form?

Thanks,

Shawn

Subject: Are forms declared publicly and/or can you declare a public sub in a form?

Kind of. You can declare a global function or sub for a form just like you can for nearly any other object. In the object navigation pane expand “Global” (scroll all the way to the top). You can create subs and functions here that anything on your form can call. You don’t even need to call it using extended reference such as form1.myFunction(). Just myFunction().

Anything you define that way will be limited to ONLY what is contained in that form. i.e. you can’t call a function from form2 and use it in form1. As someone else suggested, a better solution is to write your multipurpose subs and functions in a script library and use that script library on the forms (or other objects).

Either works. The script library is a better route to go from a technical perspective IMO. However, either option is open to you.

Subject: RE: Are forms declared publicly and/or can you declare a public sub in a form?

Thanks guys,

I currently use Libraries for both purposes,libraries and class containment. I appreciate the feedback.

Cheers,

Shawn