Lasso Soft Inc. > Home

[pk_range]

Linkpk_range
AuthorPier Kuipers
CategoryArray
Version7.x
LicensePublic Domain
Posted09 Mar 2006
Updated09 Mar 2006
More by this author...

Description

Returns an array of strings, taking several parameters such as starting- and end-point, increment, and text prefix.

Sample Usage

Usage:
[pk_range: 
	-from=, 
	-to=, 
	-by=, 
	-prefix=,
	-suffix=, 
	-pad]
"-pad" will insert zeroes in front of numbers with fewer digits than the "-to"
value.

Examples:
[pk_range: 1, 10] -> 
	array: (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)

[pk_range: -from=8, -to=24, -by=4, -prefix='my_', -suffix='_test', -pad] ->
	 array: (my_08_test), (my_12_test), (my_16_test), (my_20_test), (my_24_test)

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.

, 
	-to=, 
	-by=, 
	-prefix=,
	-suffix=, 
	-pad]
"-pad" will insert zeroes in front of numbers with fewer digits than the "-to"
value.

Examples:
[pk_range: 1, 10] -> 
	array: (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)

[pk_range: -from=8, -to=24, -by=4, -prefix='my_', -suffix='_test', -pad] ->
	 array: (my_08_test), (my_12_test), (my_16_test), (my_20_test), (my_24_test)

To Do:
Allow for an "-Alpha" parameters which should return alphabetical ranges, such
as "aaa, aba, aca" etc.

Written by Pier Kuipers, Dublin
August 2004

pier@visualid.com
http://www.pierkuipers.com/lasso.html
================================================================================
*/

	if: !(lasso_tagexists:'pk_range');
	
		define_tag:'pk_range',
			-required='From',
			-required='To',
			-optional='By',
			-optional='Prefix',
			-optional='Suffix',
			-optional='Pad';
	
			Local:'Fromhere' = (integer: #From);
			Local:'Tohere' = (integer: #To);
	
			if:!(local_defined:'By');
				local:'By' = '1';
			Else:(local:'By' == '');
			
			/if;
			
			Local:'Byhere' = (integer: #By);
	
			if:!(local_defined:'Prefix');
				local:'Prefix' = '';
			/if;
			
			if:!(local_defined:'Suffix');
				local:'Suffix' = '';
			/if;
			
			local:'iterations'=((#Tohere - #Fromhere) / #byhere);
			
			Local:'myRange' = Array;
	
			If:(#iterations > 1000);
			
				#myRange -> insert:'limit exceeded';
				
			Else;
	
				Loop: -From=#Fromhere, -To=#Tohere, -By=#Byhere;
			
					if:!(local_defined:'Pad');
						local:'Padnumber' = '';
					Else;
						local:'Padnumber' = string;
						local:'padcount'=((string:#Tohere) -> split:'' -> size);
						local:'thisloop'=((string:loop_count) -> split:'' -> size);
						If:(#padcount > #thisloop);
						loop:(#padcount - #thisloop);
							#Padnumber += '0';
						/loop;
						/If;
					/if;
					
					#myRange -> Insert: (#Prefix + #Padnumber + (Loop_Count) + #Suffix);
			
				/Loop;
				
			/If;
		
			return: #myRange;
	
		/define_tag;
		
	/If;

?>

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft