Use the Ternary Operator to Create Conditional Case Statements or Switches (AutoHotkey Tip)

While AutoHotkey Does Not Include a Conditional Case Statement, You Can Build Your Own Using the Ternary Operator

Many programming languages include Case statements which act in a manner to similar a series of If…Else If…Else statements in an abbreviated form. The simplicity of the structure provides the primary benefit of offering a series of options in semi-list form Continue reading


Using Regular Expressions to Convert Most Formatted Dates into DateTime Stamps (AutoHotkey Tool)

AutoHotkey Offers Many Techniques for Converting the DateTime Stamp (yyyymmdd) into Formatted Dates, But What About Going in the Other Direction? Use RegEx to Identify Date Formats!

DateStampThe HowLongYearsMonthsDays.ahk function calculates the difference in years, months, and days between any two dates. To manually set the two dates, the script employs two DateTime GUI controls—input dates saved in the DateTime Stamp format (i.e. yyyymmdd) and the output in years, months and days. But wouldn’t you find it easier if you could highlight the dates in any document or Web page regardless of format, then use AutoHotkey to convert and copy the DateTime Stamps directly into the DateTime GUI controls? Continue reading

Use Gui, +OwnDialogs to Glue Modal Dialogs Boxes to GUI Parent Windows (AutoHotkey Best Practice)

Save Confusion and Annoying Missteps by Creating Child Dialogs

I began working on the promised formatted date to DateTime Stamp conversion blog when I received this question from a reader:

Hi, Jack,

I’ve created a series of pop-up boxes to help me in doing telephone-service. I have two problems, both with InputBox:

  1. How can I put a comma in the prompt section? I tried things like \, and [,] but none work. I’m sure there must be a solution, but I can’t find it in browsing through your books.
  2. It is possible to include an “always on top” control for the display of an InputBox? It does not seem to work to put ”WinSet, AlwaysOnTop, ON, A” before or after an  Inputbox entry. Is there some way to make an Inputbox display automatically stay on top?

Many thanks,


Continue reading

Swapping Variable Values (Beginning AutoHotkey Tip)

Rather Than Rewriting Code, Sometimes You’ll Find It Easier to Swap Variable Values

You may not need to use this technique very often but when you do, it can save you a lot of time.

Calculating Years, Months, Days Problem

I wrote the HowLong(FromDay,ToDay) function to calculate the difference between two dates in years, months, and days. The way the function operates it starts at the first date (FromDay) and works its way forward to the second date (ToDay). If the first date occurs after the second date, the function yields bad results.

HowLongOriginally, I added a trap to notify the user when the first date occurred after the second date—offering an opportunity to try again. However, I eventually realized that I only needed to reverse order of the dates to yield the right answer. Rather than rewriting a ton of code to create a backward-looking function, I left the original logic untouched by swapping the two date values when in reverse chronological order. Continue reading

Calculating Timespans Between Dates in Years, Months, Days (AutoHotkey Function)

Calculating the Years, Months, and Days Between Two Points in Time Takes More Than Simple Mathematics

Years ago, I wrote an AutoHotkey timespan calculation function for keeping track of my grandkids ages. (I wrote about it in my Digging Deeper Into AutoHotkey e-book and you can find the original function in the GrandKids.ahk scripts.) Developing the function was a bit of a mindbender. As I remember, I just plowed through the project finding my way by trial-and-error. When I recently reviewed the script, I had a heck of a time figuring out what I had done. I know that I explained the steps in the book, but the script (even with the few comments) remained a mystery to me.

As I thought about it, I soon realized that I might write a better function if I changed how I viewed the problem. Continue reading

Updating the INI Data Table File (AutoHotkey Legal ListView Part 4)

While It Only Takes One Line of Code to Update the INI Data File, You Must Take Into Account the INI File’s Encoding. Plus, DIY Implementation of the Other Cool ListView Features

Last time, I added code to the LegalListView.ahk script to edit and update the ListView window. This time, I add one line of code to update the same data in the LegalListView.ini file.

By updating the data table file with the edits made via LegalListView.ahk, we save any changes for future use. Continue reading

Editing ListView GUI Control Data Tables (AutoHotkey Legal ListView Part 3)

Once Loaded into an AutoHotkey GUI ListView, You Can Add Tools for Editing Data

With the exception of the first column, AutoHotkey does not allow direct editing in a GUI ListView control. That forces us to create separate editing controls for changing and updating content in any of the other columns. We can either add the controls to the same GUI as in the AddressBook.ahk script (shown below)—discussed in my AutoHotkey Applications e-book—or we can create a second GUI which pops-up on demand. Since putting all the controls in the same GUI creates less confusion for the ListView functions (the functions always operate on the default GUI), you might find the AddressBook.ahk example easier to implement for your application. Continue reading