Tip of the week #1: Ctrl-Spacebar
Intro to Tip of the week
I will admit the blog has been a bit dead for a while. I have been busy with the code below, and its taking up alot of time:
Dim oKid as cKid
Set oKid=New cKid(Age:=0)
If oKid.Parent.Tired then
so instead of trying to make some big post that I can’t seem to find the energy to neither start nor finish, I want to try a series of smaller useful tips. And this will be the first one.
I am sure if you have coded anything in VBA you have run into IntelliSense, although you might not have been aware that it was called so. Basically it helps by showing you the syntax of the function, and especially the arguments required, and/or methods available on a class. Examples are when you start typing say a msgbox in vba, as soon as you hit >SpaceBar< a small tooltip will appear as seen in screenshot below
This is really useful as this helps remind you of what the arguments are, which order they come in, what type (long/string/object) of parameters they expect, and whether they are required or optional (Optional indicated by [Square brackets]) as well as the return type.
When used on a class object, such as a form, you get to see all the methods and properties of object. In a forms module, typing Me followed by dot (.) will bring up intellisense, as shown below:
Note that as I have typed me.tb (and tb is what I prefix my textboxes with) I can see that the current form has 2 named textboxes. Hitting >Tab< will then insert the selected text. So easy, because I don’t have to remember all the controls on my form, and if you follow a naming convention, its easy to filter to the type of control you are looking for. If it was a button I would just type me.cmd to see all my commandbuttons as they are prefixed with cmd. Immense timesaver.
Now most of you probably already know most if not all of the above, so now its time for the actual tip. You can “activate” or trigger IntelliSense even before typing anything, or after typing just a few letters. This is done by hitting Ctrl-Spacebar, and can be done from both a form, a module, or directly in the Immediate Pane. IntelliSense is even context aware, and using it from a form, will show you private subs and functions, as well as the global ones. So IntelliSense will not show you functions or subs you cannot call from the current scope.
This is useful if you have a lot of custom functions (or at least more functions than you can remember). For example, I have started prefixing my global functions with gf_ so typing gf_ and hitting Ctrl-Spacebar I will get a list of all my globally available custom functions. Or if I can only remember the beginning of the function name, I type a few characters, hit my Ctrl-Spacebar and get a list of the functions and subs starting with those letters.
An example is shown below, where I have a lot of functions that starts with Generate (and was written before I started the convention of using gs_)
I hope you find the information on IntelliSense useful, as well as the “Tip of the Week #1”, and don’t forget to subscribe to be notified when the next tip of the week comes out (hopefully next week….fingers crossed)