Page 1 of 1

IF / ELSE statement

Posted: 21 Nov 2017, 07:07
by euras
A simple question why the first example works and the second one not?

Code: Select all

uf = 1
If (uf = 1)
   uf = New Text
ufa := uf
MsgBox % ufa ; this one works

Code: Select all

uf = 1
ufa := (uf = 1)?(uf = New Text):("") ; this one doesn't give me any value
MsgBox % ufa
While this example works..

Code: Select all

count = 5
 result := (count > 2 and count < 10)?(count + 3):(count <= 2)?(count - 1):("10")
 MsgBox % result

Re: IF / ELSE statement

Posted: 21 Nov 2017, 07:34
by divanebaba
ufa := (uf = 1)?(ufa = New Text):("") ; this one doesn't give me any value

This (ufa = New Text) is not a value, string or something else, you can store in a variable.

Try this:

Code: Select all

uf = 1
ufa := (uf = 1)?("New Text"):("") ; this one will give you a value
MsgBox % ufa
return
"New Text" is storable into a variable.

Re: IF / ELSE statement

Posted: 21 Nov 2017, 16:34
by euras
so using this method I cannot create a new variable, just change the active one?

Re: IF / ELSE statement

Posted: 21 Nov 2017, 16:58
by A_AhkUser

Code: Select all

var = true ; string 'true'
MsgBox % var
var := "true" ; the colon-equal operator evaluates an expression and stores the result in a variable; in this case, everything that is not encloed in quotes is supposed to be the name of a variable
MsgBox % var
var := true ; true as boolean value using thecolon-equal operator - displays 1
MsgBox % var

x := (var) ? ("True", newvar:=functiontest()) : ("False", newvar:=400) ; if var is true x will be set to the string "True" and newvar will be set to the value returned by the function "functiontest"
MsgBox % x
MsgBox % newvar
x := (not var) ? ("True", newvar:=functiontest()) : ("False", newvar:=400) ; if var is false x will be set to the string "False" and newvar will be set to 400
MsgBox % x
MsgBox % newvar


functiontest() {
return "Hello, world!"
}

Re: IF / ELSE statement

Posted: 22 Nov 2017, 12:22
by euras
thank you! now it makes sense for me :)