Stuck with padding a number with zeroes.

Advanced Macro Recorder/Editor.

Moderator: Pulover

Peter_g
Posts: 6
Joined: 04 Dec 2021, 10:52

Stuck with padding a number with zeroes.

Post by Peter_g » 04 Dec 2021, 11:12

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!
Attachments
Pulover Macro Creator Format leading zeroes.jpg
Pulover Macro Creator Format leading zeroes.jpg (61.84 KiB) Viewed 1878 times

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Stuck with padding a number with zeroes.

Post by Xtra » 04 Dec 2021, 16:08

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)

Peter_g
Posts: 6
Joined: 04 Dec 2021, 10:52

Re: Stuck with padding a number with zeroes.

Post by Peter_g » 04 Dec 2021, 20:26

Thanks, it is 1.1.33.09... Tried to run it in just AHK and it works correctly. So this is a bug..

User avatar
Pulover
Posts: 612
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: Stuck with padding a number with zeroes.

Post by Pulover » 05 Dec 2021, 07:14

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.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)

Peter_g
Posts: 6
Joined: 04 Dec 2021, 10:52

Re: Stuck with padding a number with zeroes.

Post by Peter_g » 05 Dec 2021, 10:30

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.

User avatar
Pulover
Posts: 612
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: Stuck with padding a number with zeroes.

Post by Pulover » 05 Dec 2021, 12:07

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.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)

Peter_g
Posts: 6
Joined: 04 Dec 2021, 10:52

Re: Stuck with padding a number with zeroes.

Post by Peter_g » 14 Dec 2021, 05:28

Your are doing a great job! Thank you for that!

Peter_g
Posts: 6
Joined: 04 Dec 2021, 10:52

Re: Stuck with padding a number with zeroes.

Post by Peter_g » 23 Dec 2021, 04:37

Managed to do it with the Functions dialog box, it's Ok! Just needed some time to familiarize with the software:
Attachments
Format function - Ok.png
Format function - Ok.png (33.58 KiB) Viewed 1585 times

User avatar
Pulover
Posts: 612
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: Stuck with padding a number with zeroes.

Post by Pulover » 23 Dec 2021, 12:35

Well done!
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)

Post Reply

Return to “Pulovers Macro Creator”