logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 Stupid Keyboard Tricks

Posted on
2/18/2001
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
All
Product:
5, 6



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 IDE.  And 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 shortcuts.

  • When typing code, use the Code Completion feature.  For instance, consider the following code:
Dim strEmployeeName as String
Dim lngEmployeeID as Long

When typing 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 strEmployeeName .  Pretty nifty, ha?  The reason this happens is because VB keeps all the variables, functions, subs, methods, etc... 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.

  • If Visual Basic finds more than Stupid Keyboard Tricksone 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 further.

  • Here is really cool one pointed out by HENRI VAN DER WESTHUIZEN (199206260@upe.ac.za) 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 as read-only).
      • 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 property category.
    • 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
    • Miscallaneous
      • 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 mentioned.
      • 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.


  • There 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 function.

Press Ctrl-Shift-F2 and it will take you back.  These two combos have been there since the dawn of VB.

Have you ever lost the Project Explorer window?  Press Ctrl-R to bring it to life.

Do a quick save before running.  Press Ctrl-S.

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 Shift-F9.

To toggle a breakpoint, use F9.

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 Ctrl-T.

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 shortcuts

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 interest)
  • 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.


Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By Anonymous. Posted on 3/2/2006 9:38:21 PM
f**k you

#2. By Frank. Posted on 3/10/2006 11:30:04 AM
Nice list.

An addition (for windows in general but handy for programmers):
Holding the windows start button and hitting E - brings up windows explorer.
Start+D = show desktop
Start+F = windows search
Start+R = run dialog

#3. By MK. Posted on 5/9/2006 10:34:47 PM
Ctrl G-Find and Replace

#4. By cole h.. Posted on 6/5/2006 12:21:03 PM
hold ctrl+alt+shift and press question mark to make it upside down(works with exclamation)

#5. By sam. Posted on 6/9/2006 12:23:01 AM
Shift+F3 does this example "the" when you press Shift+F3 it will do this The,THE and back to normal if you press it again

if you ever need a cents sign on a number just press this ctrl+/+c

#6. By Hugh. Posted on 7/7/2006 8:34:19 AM
Thanks. My 2 year old just crashed my computer and half the power grid in the down-town area.

I guess I should have used a 5 month old.

Thanks for the tips!

#7. By qt. Posted on 9/6/2006 10:59:31 PM
how do u fix ur punctuation!?

#8. By qt. Posted on 9/6/2006 10:59:37 PM
how do u fix ur punctuation!?

#9. By girts brinska. Posted on 10/18/2006 8:52:19 PM
da why you ky

#10. By Lisa. Posted on 11/13/2006 10:58:39 PM
F11 MAXIMISES THE SCREEN

#11. By bandon w. Posted on 11/15/2006 4:59:05 AM
if your using aim, if you want to put a whole bunch of smiley without clicking them all, just hold down ctrl and any number, or hold it down and type a whole bunch of numbers at one time!

#12. By Jim. Posted on 2/7/2007 3:00:04 PM
On MS Word 2003, I accidentally just found a bunch of shortcuts 'within Find and Replace'. They are mostly formatting commands like center: ctrl-e, right: ctrl-r. There are line spacing shortcuts such as crtl-2. Are these shortcuts listed or documented anywhere? Are there advocates for their use? Thanks for listening. Jim (in search of the power users had in the early days of wordperfect)

#13. By Jocelyn. Posted on 2/13/2007 6:35:31 AM
My 11 month old has been hitting the keyboard on my Parents computer. She has hit a combination of keys that have turned the screen upside down. Does anyone know what this combo is and/or how to fix this?? Please help!!

#14. By Anonymous. Posted on 2/13/2007 2:52:41 PM
ctrl+alt+up arrow will fix it. (Down arrow flips it upsude down, side arrows flip it sideways.)

#15. By Eric. Posted on 4/20/2007 4:58:15 PM
Ctrl+Arrows doesn't move a form object around in Excel VBA 2000 and I hate trying to use the mouse! Anyone know why / how to this?

#16. By francheska. Posted on 5/4/2007 9:06:45 AM
um cole h. i tried ur ctrl+alt+shift thing to make ?marks an stuff go upside down an ya it totally didnt work.

are u sure u told me the right thing?

#17. By francheska. Posted on 5/4/2007 9:08:03 AM
um cole h. i tried ur ctrl+alt+shift thing to make ?marks an stuff go upside down an ya it totally didnt work.

are u sure u told me the right thing?

#18. By cool kid. Posted on 5/4/2007 3:50:31 PM
what about closing all windows?

#19. By Znfnhgnv. Posted on 6/13/2007 10:24:12 PM
Alt + 3=?

#20. By vbpisthu?. Posted on 6/20/2007 2:02:26 PM
In VB, during runtime, whats the key combination to directly go to a specific code snippet when an action is fired (eg., Command button click). I remember it should be a combination with CTRL key

#21. By frog. Posted on 9/26/2007 5:30:02 AM
how do you get thoses smilly faces and strange shapes like hearts????

#22. By dddd. Posted on 9/26/2007 7:18:00 AM
i pressed alt f5 and it has made all the font, taskbar, shortcuts small. how do i fix this plz its shitting me

#23. By Jim. Posted on 10/6/2007 2:09:20 PM
alt+1=? Note~The numbers can only come from the keypad, the far right on your keyboard. You cannot do it
alt+2=? on the top number keys.Thanks
alt+3=?
alt+4=?
alt+5=?
alt+6=?
alt+7=•
alt+8=?
alt+9=?

#24. By Mr. Bill. Posted on 10/17/2007 3:31:42 PM
I agree with the last guy... oh and you should put how you do special symbols like to make degree signs as in temperature

#25. By Marcello. Posted on 11/5/2007 3:51:39 PM
Help me people?

I don't know type Spanish puntuation.I could try modify my keyboard configuration. But I'm not sucessed. I need make a job work.

Thanks
Marcello

#26. By Dianaaa. Posted on 11/10/2007 12:21:12 AM
cooolllllll:P:)

#27. By Anonymous. Posted on 11/25/2007 12:25:12 AM
this is cool. great idea to help out wit us

#28. By Monique. Posted on 12/2/2007 10:38:28 PM
very cool

#29. By paddytt. Posted on 12/13/2007 2:34:32 PM
ehgwfuybrugyfbrhsdkhfgwfgearifgbdsaifgbeqrigvberuigneuringeruighrweuiguigheruigheruifgnusadivuirgfnvwiatpinwbcyiertnypsracv nnrhivpoasihcuresivhnteriwopvtnwroi vbpery nrieobn fyiutje bterio qrpli;qre;qriuwer toerw tiwqoe rtyhwqeio ]ewi rwe'/;rkew[- uqerlk; tjwe tw

#30. By Anonymous. Posted on 1/22/2008 1:21:33 AM
??

#31. By Anonymous. Posted on 1/22/2008 1:21:43 AM
??

#32. By Anonymous. Posted on 1/22/2008 1:21:45 AM
??

#33. By Anonymous. Posted on 1/28/2008 10:05:57 PM
how do u get a heart??
(using the keyboard)

#34. By Anonymous. Posted on 2/1/2008 11:21:22 PM
use he arrow keys to select a icon then press enter and the icon will open

#35. By Anonymous. Posted on 2/1/2008 11:21:27 PM
use he arrow keys to select a icon then press enter and the icon will open

#36. By Anonymous. Posted on 2/1/2008 11:24:46 PM
to get a heart press alt on the left side of the key board and the number 3 on the right side of the keyboard

#37. By Anonymous. Posted on 2/1/2008 11:24:56 PM
to get a heart press alt on the left side of the key board and the number 3 on the right side of the keyboard

#38. By Jessie Kim. Posted on 3/30/2008 5:08:58 AM
What are ways to delete URLs from history?

#39. By Anonymous. Posted on 3/30/2008 5:09:15 AM
What are ways to delete URLs from history?

#40. By Anonymous. Posted on 3/30/2008 5:09:18 AM
What are ways to delete URLs from history?

#41. By turkeymonkeyglowfishsr.. Posted on 4/7/2008 9:25:34 PM
alt+ctrl+arrow key=flip scrren

#42. By rose. Posted on 4/15/2008 12:54:42 AM
wow...that last method i would have recommended myself

#43. By rose. Posted on 4/15/2008 12:54:53 AM
wow...that last method i would have recommended myself

#44. By rose. Posted on 4/26/2008 6:16:50 PM
right back at ya' frank