Go Premium for a chance to win a PS4. Enter to Win


Trying to understand the colon equals (:=) symbol, especially in AutoHotkey (AHK)

Posted on 2014-02-13
Medium Priority
Last Modified: 2014-02-28

I frequently use a scripting language called AutoHotkey (AHK) for creating macros. There's one particular symbol (:=) which, despite my going through the documentation on a number of occasions and asking questions in the AHK form, is just not clicking.

I've seen a few comments elsewhere indicating this symbol is used in some programming languages (and occasionally in math) but I don't know if it has the same meaning. Nevertheless, I'm posting the topic on EE now in hopes that someone might be able to provide some type of explanation or analogy — maybe from a different perspective — which will enable me to grasp the concept. By the way, I have no programming background but I do feel comfortable with Excel functions & equations (not VBA, but just the in-cell functions) as well as math (up through calculus) formulas and equations. Are there relationships or syntax in either of those areas which are analogous?

Following (between the dotted lines) are some comments which were provided by one (very patient) person on the AHK forum. Included is a quotation (in italics) from the AHK docs. (The script examples are part of the docs quotation.)

"[[AHK] Variables and Expressions is] a good page for an explanation of expressions vs variables. I find this bit especially useful:

"Storing values in variables: To store a string or number in a variable, there are two methods: traditional and expression. The traditional method uses the equal sign operator (=) to assign unquoted literal strings or variables enclosed in percent signs. For example:

MyNumber = 123
MyString = This is a literal string.
CopyOfVar = %Var%  ; With the = operator, percent signs are required to retrieve a variable's contents.

Open in new window

"By contrast, the expression method uses the colon-equal operator (:=) to store numbers, quoted strings, and other types of expressions. The following examples are functionally identical to the previous ones:

MyNumber := 123
MyString := "This is a literal string."
CopyOfVar := Var  ; Unlike its counterpart in the previous section, percent signs are not used with the := operator.

Open in new window

"The latter method is preferred by many due to its greater clarity, and because it supports an expression syntax nearly identical to that in many other languages.

"Expressions are especially useful because they are required to do math and are used in function parameters."

Another link which may be helpful is here: Var := expression

By the way, I don't know if this sort of cross-forum pollination is "legal" but I figure the more comments I can get, the better chance I have of getting it.  :)

Question by:Steve_Brady
  • 3
LVL 56

Assisted Solution

by:Joe Winograd, EE MVE 2015&2016
Joe Winograd, EE MVE 2015&2016 earned 2000 total points
ID: 39858190
I haven't read your whole post yet, which I will do a little later, but when I saw AutoHotkey (my favorite programming/scripting language these days), I wanted to fire off a quick response for you. The ":=" means to assign a value to a variable. The variable getting a value assigned to it is on the left of the ":=". The value being assigned is on the right, which could be as simple as an integer, or it could be a complex expression. For example, to set a counter to zero, here's a very common line of code:


To increase a counter by one, here's another very common line of code:


This quick note may be far too simplistic for you, so I'll read your full question more thoroughly later and will respond accordingly.

Btw, you may not know this (I didn't until a few days ago), but a new community was recently established to move the language forward. The latest release at the new community has a Windows installer, an offline help file, and a compiler that turns the AHK source code (plain text) into a stand-alone/no-install executable (an EXE file).

There is excellent documentation:

...including an alphabetical command and function index:

...a good tutorial:

...and an active user forum:

Regards, Joe
LVL 56

Accepted Solution

Joe Winograd, EE MVE 2015&2016 earned 2000 total points
ID: 39858358
Now that I've read your whole post, my previous answer stands, with a few additions. First, I agree strongly with the "greater clarity" comment. Another good example of "greater clarity" is:


The above two statements produce the same result in AHK, but I much prefer the clarity of the first one.

To distinguish between the assignment operator and the Boolean "=" operator, many languages chose ":=" as the assignment operator, including Algol and Pascal. AHK managed to find a way to use both ":=" and "=" for assignments, providing some flexibility, but also some confusion to go along with it.

AHK is a great language, but has some quirks, one of which relates to the assignment operators. When parameters are fed into an AHK program, they come into variables called %1%, %2%, %3%, etc. When params come into an AHK program, I like to assign them to variables with meaningful names. So the first time I did this in an AHK script, I had these statements:


Guess what? Didn't work! The syntax in this case must be:


This is no doubt because of the percent signs around the param variables, in which case AHK wants the "=" assignment operator, not the ":=" one. There are some other rare circumstances where I go with "=" for assignment, but in nearly all cases, it's ":=". For example, take a look at the AHK program in this EE article and you'll see my heavy-duty use of ":=" as the assignment operator. Regards, Joe

Author Closing Comment

ID: 39896377
Thanks Joe
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 39896381
You're welcome, Steve. Happy to help.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question