Many people don't realize that using the keyboard
will make you a ton more productive than using a mouse to achieve the same
goals. This is particularly true for the Visual Basic
even though most of the keyboard shortcuts are described in the help
file, I see programmer after programmer using the mouse to do the keyboard's job. All
these shortcuts apply to VB6. However, most of them will also work with VB5 and
some will go even lower. So without further delay, here is your guide to being
more productive. Later, check out the section on how to discover your own
Dim strEmployeeName as String
Dim lngEmployeeID as Long
strEmployeeName you can save yourself a couple of seconds by
typing strE and then pressing Ctrl-Space to signal Visual Basic to complete
your variable. That is right, VB will append mployeeName to strE, to complete
. Pretty nifty, ha? The reason this
happens is because VB keeps all the variables, functions, subs, methods,
in memory and can pop them up whenever necessary. If you
get into the habit of using this feature, you'll shave off hours from
you development time just in a single week.
Basic finds more than one match to what you typed, it will display a popup list for you
to choose from. This is handy with long object names that have large
object hierarchies. For instance, instead of typing in
strE we typed str. Obviously there are tons of functions
that match str. So VB drops down a box that lets you select.
Eventually you will get into a habit of creating drop-down friendly variables (so
that there are less items in the dropdown) and that will speed up the coding even
Here is really cool one pointed out by
HENRI VAN DER WESTHUIZEN (email@example.com) of
South Africa. While in the Properties screen, just type CTRL-SHIFT and the
first letter of the property and you will go straight to it. A lot easier that
scrolling through all of then to get to the bottom one.
Below is a whole slew of keyboard tricks contributed by a fellow keyboard jockey
Greg Heslington. I have to admit, some of them caught me
by surprise. Furthermore, Greg provided us with an excellent Excel spreadsheet
listing various the VB shortcuts in a template manner, a la those WordPerfect 5.1 paper templates that were placed on the F keys.
Anyway, without further delay, here are Greg's tricks:
- Code Window Shortcuts
- Ctrl+F2 (5 star tip) - moves focus to the "Object" combo-box above the Code window.
...from here you can select the procedure you're editing by using DownArrow
to drop-down the combo-box's list of objects. Press the first letterof the
object name, or UpArrow/DownArrow/Home/End to navigate through the list.
Home is good for selecting the (General) section, where non-event-code
procedures live. Then, press Tab to toggle between the "Object" and
"Procedure" combo-boxes and navigate similarly. Press Return to selectone,
and you'll be back in the Code window at the correct position.
- Ctrl+Shift+F2 - I mentioned this one before. Greg adds that it
works without first pressing Shift+F2, as it cycles through the last 8
positions visited, not just where you were before you viewed the definition
of a variable.
- F3 - find the next occurrence of text last searched for
- Shift+F3 - find the previous occurrence of text last searched for
- Ctrl+F3 - find the next occurrence of selected text, or the word under the cursor
- Ctrl+Shift+F3 - find the previous occurrence of selected text, or the word under the cursor
- The general rule-of-thumb for the previous four is as follows: "Press shift to search
backwards; press ctrl to start searching for something different".
- F6 - (when the Code window is split into two panes) - toggles between the
panes. To split the panes first (or indeed un-split afterwards), press alt+W, P.
- Ctrl+Shift+F9 - clear all breakpoints
- Tab (when a block is selected) - indent the whole block
- Shift+Tab (when a block is selected) - un-indent the whole block
- Ctrl+Z - undo the last change. The last 20 changes can be backed out of.
- Ctrl+I - show the quick-info tooltip. Tells you the type of variable,or
value of a constant, at the cursor.
- Ctrl+Shift+I - show the parameter-info tooltip. Tells you the parameters
required in a function or sub call, without having to insert a spurious
comma and delete it! (which you can't do anyway in modules that are marked
- Ctrl+G - show the Immediate window.
- Ctrl+F - show the Find dialog
- Ctrl+H - show the Replace dialog
- ...within Find and Replace dialogs, the highlighted text (or the word underthe
cursor is automatically placed in the Find What field). Press Return to Find
Next, Esc to close the dialog, or alt+letter to focus and/or toggle onthe
other controls [duh...?]
- Ctrl+Y - remove the current line without having to select it. This one was
contributed by Joacim Andersson.
- Object window shortcuts (i.e. the forms)
- Shift+F4 - show the custom property pages for the selected object
- Arrow keys - UpArrow/DownArrow/LeftArrow/RightArrow
- Select a different control on the container.
- With Shift pressed, enlarge/shrink the selected control(s).
- With Ctrl pressed, move the selected control(s) around the container.
- Tab or Shift-Tab - select the next/previous control in the tab order
- Project Explorer window
- Tab - switch between projects in a group
- Down Arrow - move down the tree
- Up Arrow - move up the tree
- Right Arrow - expand a folder, or go to the first child node
- Left Arrow - collapse (if a folder) and go to the parent node
- Numeric Plus - expand the folder
- Numeric Minus - collapse the folder
- Property window
- Tab or Shift+Tab - cycle forwards/backwards through the control drop-down, the tabs, the property
name, and the property value. This method can be useful for changing (or just reviewing) several control's
properties, eg the TabIndexes (TabIndices? :-). Useful if certain controls
are on hidden areas of the form (eg on different tabs of your form) andyou
don't want to hunt them down and click (ugh!) on them.
- The "Categorized" tab in Properties is dead useful for
hiding the other properties if you're reviewing the sizes of your controls.
Just click on all the minus signs except for the one next to the "Position"
category. Did I say click?! I meant Tab to a property category, press
LeftArrow to collapse it, then press DownArrow to move down to the next
- Break Mode
- Shift+F5 - re-run from the start (surely not that useful?)
- F8 - step into the current statement
- Shift+F8 - step over the current statement
- Ctrl+F8 - run upto the statement under the flashing cursor
- Ctrl+Shift+F8 - run the rest of the current procedure and break againwhen
exiting back to the calling statement
- F8 based shortcuts can also be used from design mode, to start the project and
immediately single-step through the code, but I can imagine that stepping
through the start-up code of a big project would be very tedious. In fact I
bet you'd get a misleading impression of the program flow, because break
mode tends to suppress certain events from firing.
- Ctrl+F9 - set the statement under the flashing cursor as the next one to execute.
- Ctrl+L - view (and navigate) the call stack
- Ctrl+F4 - close the current child window (as per bog-standard Windows)
- Ctrl+F6 or Ctrl+Tab (or with Shift) - cycle forwards/backwards through the Code windows and Object windows
- Shift+F7 - go to the Object window. This is the complement of F7 whichyou
- You want to make more space for the Code window while programming?
Hiding the Project Explorer, Properties and Immediate windows is easy:-
Ctrl+R, menu, H to hide the Project Explorer window,
F4, menu, H to hide the Properties window,
Ctrl+G, menu, H to hide the Immediate window.
- Here are 2 really shortcuts courtesy of Dean Hutchings:
Assuming you have "Break On All Errors" selected, you can do the following:
Alt+F5 - continue past error dialog
Alt+F8 - step past error dialog
These are great if you want to be sure to see all errors but don't want to mess around with toggling the error trapping settings.
- Not necessarily a keyboard shortcut for VB so much as Windows in general;
any ListView (Explorer folders included) which is in report (ie, details)
view can have its column widths auto-resized by pressing Ctrl+NumericPlus.
- All I can say is: Thank you, Greg. These are surely to improve coding speed. In addition, Greg provided some
stupid mouse tricks as well, which will be included in an upcoming article.
are many more simple keyboard shortcuts that for some
reason are seldom used by programmers. Below are some of them:
Place the cursor on a function name, then press
Shift-F2 combination and it will take you to that
Press Ctrl-Shift-F2 and it will
take you back. These two combos have been there since the dawn of
Have you ever lost the Project Explorer
window? Press Ctrl-R to bring it to life.
Do a quick save before running. Press
Never select Start button. Always do a
Start With Full Compile. Either press Ctrl-F5 or hold
down the Ctrl key while pressing the Start
button. (Or as some of my less than competent co-workers call
it: The 'Play' button).
Want to do a quick comment/uncomment of your
code? See this tip.
Do you want to quickly see the value of a
variable? Place a cursor on the variable and press
To toggle a breakpoint, use
Ctrl-A will select all the code
in the Code Window. BTW, if you didn't know this one, please pack up
your copy of VB and return it to the store for a full refund. You don't
deserve to be a programmer.
Are you sick and tired of going to the Project
menu and selecting Components? Simply press
To bring up properties for any object in VB,
press F4. To bring up code, press F7
on any object.
How to discover your own keyboard
Many people ask me: "How do you figure out all
these keyboard shortcuts?" Well, beyond the usual 'look on the freaking
menu - the shortcuts are to the right' method, I also recommend the
following highly complex but much more rewarding method. An
added bonus to this method is that you'll find the undocumented tricks as
well. Please follow the directions below:
To start you will need a 5 month old
child (preferably your own, because you know how protective parents
can get) and a keyboard.
Start Visual Basic (or any other program of
Let the child pound away at the keyboard.
However, pay a lot of attention to the keys your child is pressing,
because you could miss a good one. Soon you'll see various screen come
up that normally require several mouse clicks. If you see any good
shortcuts, let us know.