Sunday, 8 January 2017

AET VBE Tools v1.1 and Line Numbers

Last time I blogged, I mentioned that my new AET VBE Tools had more stuff coming.

Well, I've been VERY busy adding new tools and settings, redesigning and also fixing bugs, both major and minor.

There are two new tools and one new feature.

Code Snippets
You can now add snippets into a procedure where the cursor is located. And the Code Snippets tool can save up to 10 different items.

Highlight Code in Excel
There's no way to highlight code in the VBE. But we're using Excel, right?

This tool copies selected procedure code to a worksheet in a new workbook, and also inserts event code to highlight cells that looks for keywords such as "If, "For" and "With" so you can see which lines of code match.

Potentially useful if you have lots of nested code!

Undo last operation
Most tools now have an undo option. So if you want to revert to how things were before the tool was used, now you can! Refer to the Help Files for details.

Line Numbers
I improved my code that works with line numbers. And as I promised last time, I'll write a bit to explain how they might be useful.

You can add line numbers like 10, 20, 30 or 10:, 20:, 30: in front of your code.

There are some rules. For example, they must be unique per procedure. Some code doesn't accept them, such as the first Case statement in a Select Case block. (Other Case statements don't have this problem). For the most part, they are okay, and my tools are designed to only add them where they are allowed.

So why use them?

They are a handy reference. Imagine giving or following directions to a house. Isn't is easier when there are street signs? You can also use code like GoTo 120, which means the code will jump to Line 120 of your procedure.

And how about an accident? Street signs are going to make things easy again. You can use line numbers in the same way an emergency services worker would refer to a street sign when writing up a report.

For example, step though the code below using the F8 key to see how it works. (Click Ctrl + G to show your Immediate Window if i's not visible)

Sub ERLDemo()
On Error GoTo 40

10 Debug.Print 1 / 0

20 Debug.Print "Today's date is " & Format(Date, "d mmmm, yyyy")

30 Exit Sub

40 Debug.Print "An error occurred on Line " & Erl

End Sub

The result...

Because an error occurred on Line 10, the code went straight to Line 40 and also told us which line of code caused the problem.

Useful? You decide. Something to consider is that you may need to edit existing line numbers if you change your code. Fortunately, my Add Line Numbers tools replace old ones with new ones, and in sequential order, with one click. Also, I've noticed that adding colons to line numbers actually makes stepping through code take longer, so unless anybody can mention a benefit, I'd stick with just using numbers by themseves. But as you guess, my tools have the option to include colons if that's your preference.

Speaking of which, download the new version of AET VBE Tools here!

No comments :

Post a Comment