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

Advertisements

New Book of Jack’s Motley Assortment of AutoHotkey Tips

 

Jack’s Motley Assortment
of AutoHotkey  Tips

A Living Book

CoverImage200This first edition of my new book Jack’s Motley Assortment of AutoHotkey Tips includes more than 80 chapters of AutoHotkey tips, tricks, and techniques. But, that only reflects the starting point for this Living book. Every six months to a year, I will add 30 or more new chapters based upon my current explorations of AutoHotkey. If you purchase this book, you will get all of these new editions free. You only need to buy this book once.

To review the “Table of Contexts” and “Index”, see this Motley Tips page. Continue reading