0

I want to execute two commands as part of a single-line If -statement:

Though below snippet runs without error, variable $F_Akr_Completed is not set to 1, but the MsgBox() is displayed properly (with "F is 0").

$F_Akr_Completed = 0
$PID_Chi         = Run($Command)

If $F_Akr_Completed = 0 And Not ProcessExists($PID_Chi) Then $F_Akr_Completed = 1 And MsgBox(1,1,"[Info] Akron parser completed. F is " & $F_Akr_Completed)

Any idea why there is no syntax-error reported when it's not functional?

1 Answer 1

3

There is no error, because

If x = x Then x And x

is a valid statement, and x And x is a logical expression. There are many ways you can do this, e.g.:

If Not ($F_Akr_Completed And ProcessExists($PID_Chi)) Then $F_Akr_Completed = 1 + 0 * MsgBox(1,1,"[Info]    Akron parser completed. F is " & 1)

But that is a bad style of coding. AutoIt is a mostly verbose language and I recommend to seperate multiple statements.

You can also assign values using the ternary operator:

$F_Akr_Completed = (Not ($F_Akr_Completed And ProcessExists($PID_Chi))) ? 1 : 0

which is the same as

$F_Akr_Completed = Int(Not ($F_Akr_Completed And ProcessExists($PID_Chi)))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.