Better syntax for this if-statement? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
KilliK
Posts: 236
Joined: 10 Mar 2016, 21:19

Better syntax for this if-statement?

08 Feb 2019, 23:45

Hello.
I am using this if-statement which works fine:

Code: Select all

name:="filename with no ext"
if (FileExist("C:\" name ".*.part")) {
Msgbox File wasn't downloaded
Do A
}
else if not (FileExist("C:\" name ".*")) {
Msgbox File wasn't downloaded
Do A
}
I wrote it like this, because the first statement is also part of the second statement, so I had to distinguish them somehow.
But since both statements do the same thing when triggered, I would like to use a better syntax, more condensed if possible.
Is there some other better way to rewrite the same code?
User avatar
Masonjar13
Posts: 1528
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Better syntax for this if-statement?  Topic is solved

09 Feb 2019, 00:20

You can combine them using the || (or) operator.

Code: Select all

if (FileExist("C:\" name ".*.part") || !fileExist("C:\" name ".*")) { ; ! inverts the statement, making false return true, like "if not"
    Msgbox File wasn't downloaded
    Do A
}
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
SOTE
Posts: 1200
Joined: 15 Jun 2015, 06:21

Re: Better syntax for this if-statement?

09 Feb 2019, 00:57

Like this should work.

Code: Select all

name:="filename with no ext"
if FileExist("C:\" name ".*.part") 
{
Msgbox File wasn't downloaded
Do A
}
if !FileExist("C:\" name ".*")
{
Msgbox File wasn't downloaded
Do A
}
KilliK
Posts: 236
Joined: 10 Mar 2016, 21:19

Re: Better syntax for this if-statement?

09 Feb 2019, 04:19

@Masonjar12 that worked very well, thank you very much.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], TiGeR and 28 guests