IF / ELSE statement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

IF / ELSE statement

21 Nov 2017, 07:07

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
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: IF / ELSE statement

21 Nov 2017, 07:34

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.
Einfach nur ein toller Typ. :mrgreen:
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: IF / ELSE statement

21 Nov 2017, 16:34

so using this method I cannot create a new variable, just change the active one?
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: IF / ELSE statement

21 Nov 2017, 16:58

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!"
}
my scripts
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: IF / ELSE statement

22 Nov 2017, 12:22

thank you! now it makes sense for me :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 209 guests