Page 1 of 1

Stuck with padding a number with zeroes.

Posted: 04 Dec 2021, 11:12
by Peter_g
I saw the topic in StackOverflow "Add leading zero to make a 4-digit number in Autohotkey" but it simply does not work for me in Pulover Macro Creator.

The expression "Format("{:o}", 255) returns 377" works fine. But I need "Format("{:04}", Number)" and it does not work!


Can anybody help me with this, please!

Re: Stuck with padding a number with zeroes.

Posted: 04 Dec 2021, 16:08
by Xtra
Verify you are using AHK v1.1.17+

Your code looks fine:

Code: Select all

var1 := 5
var1 := Format("{:04}", var1)
SendRaw %Var1%
If you are using 1.1.17+ and it still does not work there could be an issue with the pulover tool.

(I don't use pulovers just trying to help)

Re: Stuck with padding a number with zeroes.

Posted: 04 Dec 2021, 20:26
by Peter_g
Thanks, it is 1.1.33.09... Tried to run it in just AHK and it works correctly. So this is a bug..

Re: Stuck with padding a number with zeroes.

Posted: 05 Dec 2021, 07:14
by Pulover
This cannot work on PMC because of the way math expressions are held. Eval() can't tell if the given number parameter is supposed to be a string, so it must trim leading zeros. If I change that behavior, it will break math operations. There are other ways to accomplish that using string commands, but it's going to take more then one line.

Re: Stuck with padding a number with zeroes.

Posted: 05 Dec 2021, 10:30
by Peter_g
Does FormatTime function work? Substr function seems not to work either.

I need to take the time value from Excel, like 0800 or 1200, and pass it to a text field. What could be these lines of code..?

Anyway, it is very sad all this is not documented.

Re: Stuck with padding a number with zeroes.

Posted: 05 Dec 2021, 12:07
by Pulover
Peter_g wrote:
05 Dec 2021, 10:30
Anyway, it is very sad all this is not documented.
Sometimes I think people expect too much from this free tool maintained by a single coder. :lol:
I've wrote a help file and I still get questions about things that are explained there... I'm not so much motivated as to write down as many details as possible about it.

I would give you an example if I could but I'm way too busy lately.

Re: Stuck with padding a number with zeroes.

Posted: 14 Dec 2021, 05:28
by Peter_g
Your are doing a great job! Thank you for that!

Re: Stuck with padding a number with zeroes.

Posted: 23 Dec 2021, 04:37
by Peter_g
Managed to do it with the Functions dialog box, it's Ok! Just needed some time to familiarize with the software:

Re: Stuck with padding a number with zeroes.

Posted: 23 Dec 2021, 12:35
by Pulover
Well done!