Is there a way to increment a variable with a calculation and maintain the original padding? I have a variable that's either going to be 001 or 01, and when I increment it, I'd like it to maintain that formatting. So far, all I've been able to do is set everything to a fixed padding with the Format option in the calculation action.
I can use Filter to get the character count, but I don't think I can use that with the calculation format, unless I'm missing something.
I can probably split out all the zeros and append them back to the variable after the calculation, but I figured there was probably a simpler way to do this that I'm missing.
Because of how KM handles variables and text (a good thing overall, in my mind), I don't think you can really maintain the leading zeros as you go. I always just do my calculations, then use a second variable to display the formatted results to whatever level I need to show them.
There's probably an easier/better way, though; I'm just not aware of it :).
Your solution suggestion, if modified a bit, would do the job perfectly, but I'm fairly confident someone will come up with a simple solution.
I'm working on a delightful, novel solution, but it may take longer than usual because I'm watching the US election results and making breakfast at the same time.
I have a solution. I enjoyed the challenge. I made it into a subroutine macro. Basically, what I did was add up the digits "manually in my macro." If there were leading zeros, I kept the zeros. I'm sure there are other solutions, which I'm still pondering, because I like this puzzle.
So convert the number to a format by replacing every digit with 0, Then create a CalculateFormat token with the format inserted (note the doubled percentage characters all through that text which are converted to single percent characters), and then process the tokens a final time to calculate the result and format it.
Thanks, Peter, this works great! Adding token support to the format field will be a nice addition, but it's cool to see all the alternate solutions, I learned some new stuff here.
Hi guys, i’m working on a project that need to create increment line number everytime i hit a hot key. Let say i bind cmd-L for a hot key. when i press cmd-L it writes down line0001, the second time i press cmd-L it write down line0002 and so on up to line 0999. I’ve been struggling If and else for 12 hours now and couldn’t make it work Any help is appreciated
Here is my first attempt to implement a solution for you. Bear in mind that I'm only 50% sure I have understood your question. There are several things about your problem that just aren't clear to me. You will probably have to explain to me what's wrong with this macro, and then I will fix it. What this macro does is let you press a hotkey which will insert a new string, such as "line0001" in the place where the text cursor is, and if there is any text selected, it will replace the selected text with the next sequence number. I'm not sure that this is exactly what you want, but it's how I interpreted your request.
Your method is simpler, but I'm not sure the word clearer works here, because your method hides the fact that the system clipboard is being changed. Some users may benefit from seeing that the clipboard is being changed.