If inside expression? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
alesyt0h
Posts: 205
Joined: 28 Jan 2015, 20:37

If inside expression?

Post by alesyt0h » 19 Apr 2021, 17:17

Hello.

Im trying to use something like

Output := email . “@” . domain . If(email == examplemail) isvalid = true . ”,” . isvalid

The expected result in output should be:

[email protected],true

But i cant make it to work, tried several ways and none worked.

Any helps? Thank you

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

Re: If inside expression?  Topic is solved

Post by boiler » 19 Apr 2021, 17:31

One problem is your curly quotation marks (“ ”) instead of straight quotation marks (" "). Another is that you can't put an if statement in the middle of an expression, but you can use the ternary operator:
Operators in Expressions wrote:Ternary operator [v1.0.46+]. This operator is a shorthand replacement for the if-else statement. It evaluates the condition on its left side to determine which of its two branches should become its final result. For example, var := x>y ? 2 : 3 stores 2 in Var if x is greater than y; otherwise it stores 3. To enhance performance, only the winning branch is evaluated (see short-circuit evaluation).

Using your example:

Code: Select all

email := "examplemail"
domain := "gmail.com"
Output := email . "@" . domain . (email = "examplemail" ? ",true" : "")
MsgBox, % Output

alesyt0h
Posts: 205
Joined: 28 Jan 2015, 20:37

Re: If inside expression?

Post by alesyt0h » 19 Apr 2021, 17:54

Probably the curly quotes is because i wrote this post on the iphone :lol:

Thank you so much !! This is what I was looking for! Didn’t know about the existence of this ternary operator, it looks like a problem solving for many of my scripts where I have lots of lines.

Post Reply

Return to “Ask For Help”