[rp_param]

Description

Link: [rp_param]
Author: Randy Phillips
Category: Client
Version: 8.5.x
License: Public Domain
Posted: Jun. 25, 2007
Updated: Jul. 13, 2007
More by this author...
I created this  tag to bypass the "built in" error that occurs when the find->get element does not exist in a pair array. It gets values from pair arrays such as client_postparams or client_getparams without throwing an error when the element does not exist. Instead it silently returns a NULL value.

Parameters

-pairs array, required Takes an array of pairs only
-find string, required The element in the array you wish to find
-instance integer, optional Used for multiple elements of the same name to designate the instance or index of the desired element.

Sample Usage

local('fruit' = (array: 'item1' = 'apples', 'item2' = 'bananas', 'item1' = 'strawberries', 'item3' = 'oranges'));

(rp_param: -pairs=(#fruit), -find='item1');

//->apples

(rp_param: -pairs=(#fruit), -find='item1', -instance=2);

//->strawberries

(rp_param: -pairs=(#fruit), -find='item1', -instance=3);

//->NULL

(rp_param: -pairs=(#fruit), -find='item7');

//->NULL
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
define_tag:'param', -namespace='rp_',
	
	-required='pairs', -type=array,
	
	-required='find',
	
	-optional='instance';
	
	!(local_defined:'instance') ? local('instance' = 1);
	
	!(local_defined:'value') ? local('value' = NULL);
	
	local('param_count' = #pairs->(find:#find)->size);
	
	
	loop(#param_count);
	
		local('value' = #instance <= (loop_count) ? #pairs->(find:#find)->(get:#instance)->value | NULL);
	
	/loop;
	
		return: #value;
		
/define_tag;

 

Related Tags



Comments

06/25/2007, Johan Sölve
Horray!
Great, Randy!
Email:


Password:



Newest

Most Popular

Support tagSwap.net