AHK: How to Use IF/ELSE in a GUI

Back to a Simple Box…

Important Commands to Note:

Gui, Add, Checkbox, Variable4UserInput*, TextToDisplay
Stored variable is 1 if checked, 0 if unchecked

This is a continuation of How to Make a User Interface except this is the part where the variables actually make something happen. Start off with a simple GUI, like this:


Now Add the IF/ELSE

When the user presses OK, the program should look at the user input and think:
1. If English is checked, I should say Hello.
2. If Spanish is checked, I should say Hola.
3. If the lazy bastards didn’t check anything, I should say something anyway.

Note that both checkbox variables start with a v, but inside the IF/ELSE the v is not needed. Actually, I just tried it, and it screwed up my IF/ELSE. Don’t include the v.

For reference, the bare bones IF/ELSE code looks like this:

If ( Expression )
Do this

else if ( Expression )
Do this

Do this


Plugged in and translated, the IF/ELSE portion of the code should have expressions for both checkbox variables. If the user checks a box, the variable has a value of 1, so the code in between the { } will run.


If all has gone well, the code should produce this:


In Case of Errors:

Typing the brackets on the same line will give you an error message that took me approximately 30 minutes of Googling to figure out. Put each bracket on a new line if you start getting this error.


Also, the IF/ELSE code will not recognize your variables if you enclose them in %’s. The program will just go to the last MsgBox.





2 Replies to “AHK: How to Use IF/ELSE in a GUI”

  1. you finally enabled comments! nice to see an update. what would you change about autohotkey, if anything?

    personally, i would make the written syntax (which you complain about) a little more like your gui boxes: not so much required punctuation! im very biased on this, obviously 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: