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:

BaseGUI

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
}

else
{
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.

IFELSE2

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

GIFforIFELSE

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.

IFELSE-ERROR1

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.

Error2

 

 

 

Advertisements
Tagged , , , , , ,

2 thoughts on “AHK: How to Use IF/ELSE in a GUI

  1. codeinfig says:

    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 🙂

    Like

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: