Macro Creator - Converting number to zero padded string

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tfountain
Posts: 7
Joined: 23 Jan 2014, 18:47

Macro Creator - Converting number to zero padded string

24 Jan 2014, 11:41

Hello, first let me say nice tool, it's saving my butt applying configuration changes to an internal tool of ours that I need to replicate later! I am having one issue though. I am attempting to zero pad a variable based on the A_Index variable. However all of my attempts have not worked (I tried this for literally 4 hours yesterday!). My result is always a whole number (not padded) or zero (I'm assuming my syntax generated an error). Here are the two main samples I've tried (adding and converting to string, or just concatenating into a string):

Code: Select all

SubStr(100 + %A_Index%, -1)

Code: Select all

SubStr(100 %A_Index%, -1)
Both these are examples are embedded within an Assign Variable command using the := operator and with Expressions checked on. My goal is to get a two character, zero (left) padded string. Here is the full example script that just produces a number in all situations. I am obviously looking over something - any tips on accomplishing this task would be awesome.

Code: Select all

[PMC Code]|F3||1|Window|1|Macro1
1|[LoopStart]|LoopStart|15|0|Loop|||||
2|[Assign Variable]|varA := SubStr(100 + %A_Index%`, -1)|1|0|Variable|Expression||||
3|[Assign Variable]|varB := SubStr(100 %A_Index%`, -1)|1|0|Variable|Expression||||
4|[Assign Variable]|varC := SubStr(100 . %A_Index%`, -1)|1|0|Variable|Expression||||
5|[Assign Variable]|varD := SubStr("100" + "%A_Index%"`, -1)|1|0|Variable|Expression||||
6|[Assign Variable]|varE := SubStr("100" "%A_Index%"`, -1)|1|0|Variable|Expression||||
7|[Assign Variable]|varF := SubStr("100" . "%A_Index%"`, -1)|1|0|Variable|Expression||||
8|[MsgBox]|varA: %varA%`nvarB: %varB%`nvarC: %varC%`nvarD: %varD%`nvarE: %varE%`nvarF: %varF%|1|0|MsgBox|262208||||
9|[Assign Variable]|varA := |1|0|Variable|||||
10|[Assign Variable]|varB := |1|0|Variable|||||
11|[Assign Variable]|varC := |1|0|Variable|||||
12|[Assign Variable]|varD := |1|0|Variable|||||
13|[Assign Variable]|varE := |1|0|Variable|||||
14|[Assign Variable]|varF := |1|0|Variable|||||
15|[LoopEnd]|LoopEnd|1|0|Loop|||||
moved from Scripts and Functions
Last edited by tfountain on 24 Jan 2014, 12:24, edited 1 time in total.
User avatar
AfterLemon
Posts: 85
Joined: 30 Sep 2013, 14:27
Location: Ohio, USA

Re: Converting number to zero padded string

24 Jan 2014, 11:53

This is not a script or a function, but here's your help:

Code: Select all

SetFormat, FloatFast, 08  ;8 total places, 0-padded to the left
AHK:=1  ; Start with a number, integer
AHK+=0.0  ; Add any floating point "number"
MsgBox,%AHK%  ; Output
HOME: Windows 11 Pro | AMD Ryzen 7 5800X 8-Core @ 4.50GHZ | 64GB RAM
MOBILE: Samsung Galaxy Note 10+
tfountain
Posts: 7
Joined: 23 Jan 2014, 18:47

Re: Converting number to zero padded string

24 Jan 2014, 12:02

Hey lemon, thanks for the help! I assume this would run in AHK? How would that translate into Macro Creator? Sorry for such novice questions as I just picked up this tool yesterday lol.
User avatar
AfterLemon
Posts: 85
Joined: 30 Sep 2013, 14:27
Location: Ohio, USA

Re: Converting number to zero padded string

24 Jan 2014, 12:08

That would work in AHK, but I've never used Macro Creator. Someone else will probably be able to help you a bit more.
HOME: Windows 11 Pro | AMD Ryzen 7 5800X 8-Core @ 4.50GHZ | 64GB RAM
MOBILE: Samsung Galaxy Note 10+
tfountain
Posts: 7
Joined: 23 Jan 2014, 18:47

Re: Macro Creator - Converting number to zero padded string

24 Jan 2014, 12:27

Definitely works in AHK! Now I just need to figure out how to reverse engineer this into MC! I changed the title of the thread also so it's obvious this is a question for MC.

Code: Select all

SetFormat, FloatFast, 02
Loop, 15
{
	varA := A_Index + 0.0
	MsgBox, 262208, , varA: %varA%
	varA := ""
}
Return
tfountain
Posts: 7
Joined: 23 Jan 2014, 18:47

Re: Macro Creator - Converting number to zero padded string

24 Jan 2014, 15:24

I think I have it figured out finally.

Code: Select all

[PMC Code]|F3||1|Window|1|Macro1
1|[LoopStart]|LoopStart|15|0|Loop|||||
2|SubStr|varA := 00%A_Index%, -1|1|0|Function|||||
3|[MsgBox]|varA: %varA%|1|0|MsgBox|262208||||
4|[Assign Variable]|varA := |1|0|Variable|||||
5|[LoopEnd]|LoopEnd|1|0|Loop|||||
User avatar
AfterLemon
Posts: 85
Joined: 30 Sep 2013, 14:27
Location: Ohio, USA

Re: Macro Creator - Converting number to zero padded string

24 Jan 2014, 15:30

Just looking that over, it seems to suggest that it will work the same as your first two examples, both of which you said will NOT work. How is that possible?

One thing you didn't actually do correctly with your first examples, although they STILL will fail if you try to do math without SetFormat

Inside a function, such as SubStr(), you must not use %% around vars unless you want double-deref.
HOME: Windows 11 Pro | AMD Ryzen 7 5800X 8-Core @ 4.50GHZ | 64GB RAM
MOBILE: Samsung Galaxy Note 10+
tfountain
Posts: 7
Joined: 23 Jan 2014, 18:47

Re: Macro Creator - Converting number to zero padded string

24 Jan 2014, 16:45

Hey Lemon, I think there are a few syntax tweaks with using Macro Creator where quotes and percentage signs are required, but when you export to an AHK script it converts it nice. For example, the previous post is the script file for Macro Creator. That same script generates this AHK code:

Code: Select all

Loop, 15
{
	varA := SubStr(00 A_Index, -1)
	MsgBox, 262208, , varA: %varA%
	varA := ""
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, peter_ahk and 229 guests