AnsweredAssumed Answered

Buttons and scripts working together

Question asked by scubed_1 on Dec 5, 2009
Latest reply on Dec 6, 2009 by S W

Title

Buttons and scripts working together

Post

I am a newbie with Filemaker. When I originally designed a fairly complex system, I found that my system was filled with lots of scripts - one for each button - instead of using one script that would recognize that a button was pressed and then execute code within the same script, based on the button chosen. I created complex state charts to represent all the possible choices of buttons and code on one or a group of layouts. I wanted a way to keep all the code together instead of trying to remember which script was used for what button and in what state...

 

To get around this, I came up with a scheme that I would like to share. I am sure that there are other ways to work this problem, but this is what I came up with:

 

I created a general script, called ButtonID, that is called by every button on the layout. The button passes a script parameter with the unique button name. The 'Current Script' setup option for each button is set to "resume". The ButtonID script is one line. It simply sets a global variable - $$Button - to the passed script parameter. The main script that does the button interpretation executes a 'pause/continue' step and waits for the the resume, at which point it checks the $$Button variable to determing what button was pressed. Using this method, I am able to keep all code for a given layout in the same script, making maintenance, debugging and the addition of new buttons much easier.

 

This works really well for me. The only drawback is that it is not possible to execute most of the pull down menu options when the layout is waiting for a "resume" from one of the buttons, although the script debugger and data view work fine.

 

I'm not sure if anyone else has suggested this, but if this is a redundant post, accept my apologies.

 

If anyone wants more clarification, please let me know. Hope this is helpful.

Outcomes