A_AhkVersion compare error Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
vmech
Posts: 356
Joined: 25 Aug 2019, 13:03

A_AhkVersion compare error

Post by vmech » 26 Nov 2022, 14:01

Can anyone explain why this simplest code get error ?

Code: Select all

MsgBox(A_AhkVersion < '2')
Image
Please post your script code inside [code] ... [/code] block. Thank you.

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: A_AhkVersion compare error

Post by kczx3 » 26 Nov 2022, 14:53

String literals that are pure numbers are always (almost?) interpreted as numbers. So your quotes ‘2’ is actually 2 I think? Either way, why not use the VerCompare function?

vmech
Posts: 356
Joined: 25 Aug 2019, 13:03

Re: A_AhkVersion compare error

Post by vmech » 26 Nov 2022, 15:15

kczx3 wrote:
26 Nov 2022, 14:53
String literals that are pure numbers are always (almost?) interpreted as numbers.
Apparently not always.
kczx3 wrote:
26 Nov 2022, 14:53
So your quotes ‘2’ is actually 2 I think? Either way, why not use the VerCompare function?
Because I read an example in the documentation, and decided to use it, changing it a little.
Apparently it was wrong :lol:

Anyway, 2.0-beta.15 is lesser than 2.0 :shock:

Code: Select all

MsgBox(VerCompare(A_AhkVersion, '2.0'))	; <= -1
Only this code works well:

Code: Select all

MsgBox(SubStr(A_AhkVersion, 1, 3) < '2.0')	; <= 0
Or

Code: Select all

MsgBox(InStr(A_AhkVersion, '2',, 1) = 1)	; <= 1
Last edited by vmech on 26 Nov 2022, 17:06, edited 1 time in total.
Please post your script code inside [code] ... [/code] block. Thank you.

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: A_AhkVersion compare error  Topic is solved

Post by lexikos » 26 Nov 2022, 16:53

Greater (>), less (<), greater-or-equal (>=), and less-or-equal (<=). The inputs are compared numerically. A TypeError is thrown if either of the inputs is not a number or a numeric string.
Source: Variables and Expressions - Definition & Usage | AutoHotkey v2

vmech wrote:
26 Nov 2022, 15:15
Anyway, 2.0-beta.15 is lesser than 2.0 :shock:
That is correct. -beta.15 is a pre-release tag. Pre-releases literally come before the release. v2.0 would be the final release, which hasn't come out yet. This is why #Requires AutoHotkey v2.0 will give you an error.

If you want to permit pre-release versions, VerCompare to "2-" or "2.0-", not "2" or "2.0".

Post Reply

Return to “Ask for Help (v2)”