function syntax issue?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

function syntax issue?

Post by newcod3r » 24 May 2022, 23:02

Don't understand why it says this?

Code: Select all

Error: Missing ")" before :

Code: Select all

f10::sortFolders(prop:-System.DateModified)
sortFolders(modifier) {
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
	if (oWin.HWND = hWnd)
	{
		oWin.Document.SortColumns := "%modifier%" ;sort by date modified descending (newest first)
		break
	}
}
oWin := ""
return
}

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: function syntax issue?

Post by Rohwedder » 24 May 2022, 23:39

Hallo,
the single line:

Code: Select all

(prop:-System.DateModified)
leads to same error.
The parentheses turn on the expression syntax, but this expression is not resolvable.
Try:

Code: Select all

f10::sortFolders("prop:-System.DateModified")
sortFolders(modifier) {
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
	if (oWin.HWND = hWnd)
	{
		oWin.Document.SortColumns := modifier ;sort by date modified descending (newest first)
		break
	}
}
oWin := ""
return
}

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: function syntax issue?

Post by boiler » 25 May 2022, 05:59

@newcod3r — Both changes Rohwedder made were to correct very fundamental expression syntax errors. You should read and re-read that section of the documentation until you fully understand how to write expressions and when they are used instead of legacy syntax. Everyone makes mistakes/oversights when writing code, but once things like this are flagged as errors or your script isn’t working correctly, these mistakes should be evident to you at this point.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: function syntax issue?

Post by newcod3r » 25 May 2022, 06:36

Thank you both. I would have thought legacy syntax is interchangeable with the modern version. Ok, will read the docs again.

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: function syntax issue?

Post by boiler » 25 May 2022, 06:39

No, definitely not. Expressions are required where expected, such as function call parameters and after the expression assignment operator :=. See Expressions vs. Legacy Syntax for a full discussion on when to use each.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: function syntax issue?

Post by newcod3r » 25 May 2022, 07:28

ok noted. If I'm writing a toggle, will it work within a function parameter?

normally I will write it like this

Code: Select all

SendInput, % "{Text}SendInput % ((Toggle := !Toggle) ? ""A"" : ""B"")"
But I'm not sure how to put it within a parameter.

The inverse sorting is as such:

Code: Select all

 "prop:+System.DateModified;"

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: function syntax issue?

Post by boiler » 25 May 2022, 08:02

newcod3r wrote: normally I will write it like this

Code: Select all

SendInput, % "{Text}SendInput % ((Toggle := !Toggle) ? ""A"" : ""B"")"
Well, that line doesn't toggle anything. It sends everything past the {Text} exactly as shown, which I don't think you mean. What it ends up sending would itself be a correct example of a toggle. I am guessing you use that line with a hotkey to write an example of a toggle into your script. What I think you mean is the following, which is the text that results from executing the above line:

Code: Select all

SendInput % ((Toggle := !Toggle) ? "A" : "B")

newcod3r wrote: But I'm not sure how to put it within a parameter.

The inverse sorting is as such:

Code: Select all

 "prop:+System.DateModified;"
I assume you mean within a function parameter because the above is also a parameter to the SendInput command, which is why you have to force an expression if you don't want to use command/legacy syntax. Basically it's the same except you don't need to force an expression because function parameters are already expressions. So your string "prop:+System.DateModified;" would be one result of the ternary operation, and you'd have whatever string you want as the other result:

Code: Select all

f10::sortFolders((Toggle := !Toggle) ? "prop:-System.DateModified" : "other string")

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: function syntax issue?

Post by newcod3r » 25 May 2022, 08:32

Well, that line doesn't toggle anything. It sends everything past the {Text} exactly as shown
Yes, that's correct. I program these shortcuts within notepad++ so I don't need to recall the exact syntax it is written in, which partly explains why I might not be that familiar with it now.
boiler wrote:
newcod3r wrote:
The inverse sorting is as such:

Code: Select all

 "prop:+System.DateModified;"
I assume you mean within a function parameter because the above is also a parameter to the SendInput command, which is why you have to force an expression if you don't want to use command/legacy syntax. Basically it's the same except you don't need to force an expression because function parameters are already expressions. So your string "prop:+System.DateModified;" would be one result of the ternary operation, and you'd have whatever string you want as the other result:

Code: Select all

f10::sortFolders((Toggle := !Toggle) ? "prop:-System.DateModified" : "other string")
Yes, this is clear. Thank you very much.

It's weird though that errors occur only on the NAME property.. and I'm not sure why?
image.png
image.png (76.76 KiB) Viewed 466 times

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: function syntax issue?

Post by boiler » 25 May 2022, 10:05

Probably because prop:System.Name is not the correct property designation. I believe it should be prop:System.ItemNameDisplay.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: function syntax issue?

Post by newcod3r » 25 May 2022, 17:06

ah yes you're right. thanks!

Post Reply

Return to “Ask for Help (v1)”