[pk_range]

Description

Link: [pk_range]
Author: Pier Kuipers
Category: Array
Version: 7.x
License: Public Domain
Posted: Mar. 09, 2006
Updated: Jan. 01, 0001
More by this author...
Returns an array of strings, taking several parameters such as starting- and end-point, increment, and text prefix.

Parameters

-from integer, required Starting Point
-to integer, required End Point
-by integer, required Incremental Value
-Prefix string, optional
-Suffix string, optional
-Pad boolean, optional

Sample Usage

Usage:
[pk_range: 
	-from=<integer>, 
	-to=<integer>, 
	-by=<integer>, 
	-prefix=<string>,
	-suffix=<string>, 
	-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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?lassoscript

/* 
================================================================================
Range Custom Tag
for use with Lasso Professional 7

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

Usage:
[pk_range: 
	-from=<integer>, 
	-to=<integer>, 
	-by=<integer>, 
	-prefix=<string>,
	-suffix=<string>, 
	-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

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net