Link | Inc_Serial_No |
Author | Marc Lucke |
Category | String |
Version | 8.5.x |
License | Public Domain |
Posted | 17 Nov 2006 |
Updated | 17 Nov 2006 |
More by this author... |
for any string ending with a series of numbers, will increment that number by 1 (default) or by the argument "By" if supplied. Respects leading "0" padding. A negative "By" argument MAY be supplied to DECREMENT the value instead, but this tag will fail if it decrements the tag beyond zero (what behavior is desired? clocking?). For this reason negative values for "By" are not recommended.
Only tested with 8.5.1 Is probably just fine for lower versions, just can't say.
Inc_Serial_No: -Serial_No: 2006-0099; Result: 2006-0100 Inc_Serial_No: -Serial_No: 2006-0099, -By=5; Result: 2006-0104 Inc_Serial_No: -Serial_No: 2006-0099, -By=-5; Result: 2006-0094 Inc_Serial_No: -Serial_No: 2006-0000, -By=-1; WILL FAIL with error -4
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.
[ Define_tag: 'Inc_Serial_No',-Required='Serial_No',-Optional='By'; !(Local_Defined: 'By') ? Local: 'By'=1; Fail_If: #Serial_No !>> (regexp: '\\d$'), -1, '[Inc_Serial_No] requires that its parameter end with a number'; Fail_If: !(String_IsNumeric: #By), -2, '[Inc_Serial_No] requires that the parameter "By", if specified, is numerical'; Fail_If: #By >> '.', -3, '[Inc_Serial_No] cannot increment by non-integer amounts'; Local: 'num'=(String: (String_FindRegExp: #Serial_No,-Find='\\d+$')->(Get: 1)); Local: 'length'=#num->Size; #num=(String: (Math_Add: #num,#By))->(PadLeading: #length,'0') &; Fail_If: #num<0, -4, '[Inc_Serial_No] is not written to decrement serial numbers and doesn\'t know what to do when the result is negative'; #Serial_No=(String_ReplaceRegExp: #Serial_No, -Find='\\d+$', -Replace=#num); Return: #Serial_No; /Define_tag; ]
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft