Collecting field objects and setting data

Here is a bit of openScript that many developers may have used in their projects:
- step i from 1 to n
text of field ("a" & i) = myVar [ i ]
end step
- Create an example page similar to the one shown below. It has seven field with each named "a1", "a2", "a3", ... "a7". The fields can be grouped or left as individual objects on the page (which is what we did in this example). To guarantee that they will be ordered in a predictable way, make sure to layer them in the order in which you wish to collect them for maniplulation. We only added the intial text as a reference for the sake of this example. In production use, the fields would probably contain boiler plate text or none at all.
- For this example, we also put our source string in a field called "Source_Values" at the bottom of the page and we created a button to hold the actions to be executed in this example.
- We created 3 variables for this example. They are objects, tmp, and n.
- Now build the actions for the on click event of the "Execute Actions" button as shown below.
The result of pgTBgetObjects() puts the unique ToolBook ids or their names into the array objects.
Next we prepare the corresonding array tmp to hold the values that will be put into each field collected by pgTBgetObjects().
Our next actions use a for each loop to set the data for each object in the objects [ ] array. We use the variable n as the placeholder to get the current object id being maniplulated by the current loop.
Finally, we use pgTBObjSet() to actually insert the data into the current object being manipulated in the loop. - Export your sample and observe the result. You can also download the ToolBook source file that we used to build this example.