Basic understanding, based on example "Sort"

Get help with using AutoHotkey and its commands and hotkeys
Posts: 252
Joined: 21 Sep 2014, 14:38
Location: CH

Basic understanding, based on example "Sort"

29 Jul 2019, 05:32

(Question on base of 3rd hour on try and error)

It seems that the usage of Lisp influences my basic understanding of AHK again and again..

I have a string:

Code: Select all

teststring = A,B,D,C
In Lisp I would use something like

Code: Select all

if (= (sort teststring) teststring)
But in AHK "sort" does not return a value, it changes always the variable. Right?
So I have to do something like this:

Code: Select all

teststring_2 = %teststring%
sort teststring
sort teststring_2, u

if teststring = teststring_2
Or total fail?
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
Posts: 4339
Joined: 17 Jul 2016, 01:02

Re: Basic understanding, based on example "Sort"

29 Jul 2019, 06:09

You are one the right track. However, I would recommend you read about expressions (expression) and legacy syntax. Understanding this is very important. It is recommended to avoid legacy if and legacy assignment, in your example it would be like this,

Code: Select all

teststring_2 := teststring			; Expression assignment

if (teststring = teststring_2)		; if (expression)
Also, assuming you are trying to find if teststring contains any duplicate items, you can just check errorlevel after sorting with the u option.
sort wrote: U: Removes duplicate items from the list so that every item is unique. ErrorLevel is set to the number of items removed (0 if none).

Return to “Ask For Help”

Who is online

Users browsing this forum: bmilleridentco, Franktic, Google [Bot], jfbreez, jlpsiinc88 and 159 guests