Getting an Item from a List


There might be times when you have posted data to a Database and want to do a query and return a list of values.  For instance, you could do a query where you are looking for a user's first name, their last name, and their company.  You can easily set up the ASP to write back to the ToolBook application this information as a comma-separated list such as Tom,Hall,TCC Publishing.  The problem then is that we need a way in the ToolBook application to separate this information out and store the values into variables in ToolBook such as FirstName="Tom", LastName="Hall", and CompanyName="TCC Publishing".

Thanks to some great stuff written and freely supplied to the ToolBook Community by Denny Dedmore this is easily accomplished with a shared action. One of these is Item.  The entire collection can be found by clicking here.

The code is rather lengthy and a bit complicated, but the great thing about it is that you don't need to dissect it in order to use it. The main thing you need to know is the Parameters that are expected.

There are three Parameters: itemNumber which is the position of the item in the list, str which is the list (which has been defined as data here), and the delimiter which is a comma in this list.

Now all we need to do is write code for a button to get one of the items from the list:

Here we set the data variable to whatever the list is equal to. In the demo, you just type the list. In a real application, this would be a list populated by a query of the Database.  Next in the code, we execute the Shared Action, getting itemNumber1, store that information in a variable named item1data, and then we display it with an Alert.

Click here to see it in action.