Page 1 of 1
function syntax issue?
Posted: 24 May 2022, 23:02
by newcod3r
Don't understand why it says this?
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
}
Re: function syntax issue?
Posted: 24 May 2022, 23:39
by Rohwedder
Hallo,
the single line:
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
}
Re: function syntax issue?
Posted: 25 May 2022, 05:59
by boiler
@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.
Re: function syntax issue?
Posted: 25 May 2022, 06:36
by newcod3r
Thank you both. I would have thought legacy syntax is interchangeable with the modern version. Ok, will read the docs again.
Re: function syntax issue?
Posted: 25 May 2022, 06:39
by boiler
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.
Re: function syntax issue?
Posted: 25 May 2022, 07:28
by newcod3r
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:
Re: function syntax issue?
Posted: 25 May 2022, 08:02
by boiler
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:
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")
Re: function syntax issue?
Posted: 25 May 2022, 08:32
by newcod3r
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:
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 (76.76 KiB) Viewed 489 times
Re: function syntax issue?
Posted: 25 May 2022, 10:05
by boiler
Probably because prop:System.Name is not the correct property designation. I believe it should be prop:System.ItemNameDisplay.
Re: function syntax issue?
Posted: 25 May 2022, 17:06
by newcod3r
ah yes you're right. thanks!