SetFormat not working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DerMaxPower
Posts: 2
Joined: 23 Oct 2017, 07:43

SetFormat not working

23 Oct 2017, 08:01

I have scripted a littlle ToolTip Calculator. Now I am trying to set different ammounts of decimal places through a GUI. The GUI is working fine but when I try to set the decimal places through:

Code: Select all

Label:
SetFormat, Float, 0.%Var%
Return
Nothing changes. When I set up something similar in the top of the code (execute once in the beginning) it works just fine.
Am I missing something?

I have also tried

Code: Select all

Numpad1::
SetFormat, Float, 0.2
Return

Numpad2::
SetFormat, Float, 0.5
Return
But this does not work either.
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: SetFormat not working

23 Oct 2017, 08:55

Sets the format of integers and floating point numbers generated by math operations.
It becomes active only after a math operation.

Code: Select all

a:=5/3
SetFormat, float, 0.2
msgbox % a

a +=0
msgbox % a
DerMaxPower
Posts: 2
Joined: 23 Oct 2017, 07:43

Re: SetFormat not working

23 Oct 2017, 09:32

It becomes active only after a math operation
Yes. I know that. I had the test code:

Code: Select all

TV = 1.12345678902

Numpad1::
EnvAdd, TV, 1
MsgBox, %TV%
Return

Numpad2:
SetFormat, Float, 0.5
Return

Numpad3::
SetFormat, Float, 0.2
Return
My goal was to switch with Numpad2 and Numpad3 between 2 and 5 decimal places. That didn't work.
But your answer solved my problem. Because I remembered that (for some reason) these "options" aren't set globaly. They are set for each hotkey. So if you have the code:

Code: Select all

Numpad1::
SetFormat, Float, 0.5
[Some math operation]
Return

Numpad2::
[Some math operation]
Return
and press Numpad1 and after that Numpad2, Numpad1 will have 2 decimal places and Numpad2 the standard (6), even though SetFormat was executed before you pressed Numpad2 (i hope this explanation was understandable).

Now another (related) question: Is it possible to activate SetFormat with a hotkey so that it acts globally?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: SetFormat not working

23 Oct 2017, 12:52

SetFormat is due to be removed from AHK v2, so I would recommend looking at Format instead.

See FORMAT FUNCTION EXAMPLES at:
jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, jameswrightesq and 289 guests