Do you want to quickly add dynamic blocks of comments into your code?! In this post, we’ll go over a really useful hack to make your life easier when commenting your Power Fx, which includes a dynamic date/time stamp!
Table of Contents
ToggleCommenting, why should I care?
Commenting your Power Fx code is a fantastic habit to get into, if you’re not already doing it. You might understand your code but what if you leave or move onto another project, will others understand your logic? It’s generally considered a good developer practice to add comments to your code, low code is no different.
In fact, rumour has it that if you routinely don’t add comments to your code, sooner or later you’re gonna get elbow dropped from the top rope.
Low code does not mean low standards.
Good reasons to comment your code
This is not exhaustive by any means, but a few good reasons why you should add comments to your Power Fx:
 – Add additional context to complex code blocks
– Helps you remember what you were doing when coming back to the code in future
– Assists others with understanding what you were doing when helping or debugging
– Helps to log when changes were made and by who
– Acts as a key communication tool for co-developers
– Leave examples of alternative working methods
The faster way to add comments
Follow the simple steps below for a nice little hack to take some of your commenting pain away!
1) Visit the AutoHotkey website and click ‘Download’
2) Select ‘Download v2.0’
3) Once downloaded, run the setup.exe file
4) Select ‘Current user’, then click Install
5) When installed, select ‘New Script’
6) Give your new script a name and select a file location. Ensure ‘Empty’ is selected, then click ‘Create’
7) Navigate to the file location you specified, right click on the created .ahk file and open with your text editor of choice:
8) Copy all of the code in the grey box below, paste it into the text editor, then save the file
#Requires AutoHotkey v2.0
#SingleInstance
;v1.0.0.1 Platforms of Power
;Added Help Screen on start up and hotkey CTRL ALT H
Help
^!c:: ; CTRL ALT C for Comment Block
{
date := FormatTime("dd/MM/yyyy h:mm tt")
SendInput "/*`n______________________________________________`n" date " - " A_UserName " `n`n______________________________________________`n`*/{Up 2}"
}
^!r:: ; CTRL ALT R for Infinity Form Descriptor
{
date := FormatTime("dd/MM/yyyy h:mm tt")
SendInput "/*`n______________________________________________`n" date " - " A_UserName " `n__Record Schema for this Infinity Form__`n`n______________________________________________`n`*/{Up 2}"
}
^!m:: ; CTRL ALT M for One Liner Comment
{
date := FormatTime("dd/MM/yyyy h:mm tt")
Send "// " date " | " A_UserName ": "
}
^!h:: ;CTRL ALT H
{
Help
}
Help()
{
MsgBox "Commenting Script Enabled :D`n`nFor Comment Blocks, CTRL + ALT + C`n`nFor Single Line comments it's CTRL + ALT + M`n`n EXPERIMENTAL: Start a new Patch() command with CTRL + WIN + P`n`n To see this help screen, CTRL + ALT + H"
}
9) Right click on the .ahk file and select ‘Run script’. Once enabled, the script will simply carry on running in the background
If successful, you’ll see the following popup showing the keyboard shortcuts you can use for faster comment generation!
10) You can now use the kotkey combinations when editing a Canvas App or Custom Page!
Using the Hotkeys in Power Apps
To automate a single line comment, hold down CTRL + ALT + M:
To automate a comment block, hold down CTRL + ALT + C:
If you forget either of those, simply use CTRL + ALT + H to see the Help popup:
Bonus benefit!
Aside from maintaining good coding standards, this AutoHotkey approach can also help you quickly find changes you or others have made. Search for the user using the ‘Search’ functionality in the designer to get a filtered view of where the comments exist:
Script housekeeping
If you’d like to stop the script at any time, right click the Auto Hot Key icon in your system tray & select ‘Exit’. You can use the same method to Pause or Edit the script too.
If the script is paused, you’ll need to use the above to ‘Reload Script’ to active the Auto Hot Keys again. If you shut down your device completely, you’ll need to navigate to the script file to run it again (as per step 9 above).
Hopefully this cheat helps you comment your Power Fx faster, ensuring your code has the relevant context and adhering to good practice at the same time. Let me know in the comments below if you’ve implemented the above!
Great tip Craig. I just installed it. Love it!
nice article, will definitely be installing this
great! thanks for the insight
Nice one Craig! I’m also using this script hack for a hotkey that opens and closes the formular bar!
Thanks for sharing!