Better syntax for this if-statement? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
KilliK
Posts: 255
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: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

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: 1426
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
}
User avatar
KilliK
Posts: 255
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 (v1)”

Who is online

Users browsing this forum: Billykid, Descolada, Haris00911, Swiftly9767 and 287 guests