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

Compare Databases with SQL Effects Clarity
 
 How to quickly (really quickly) comment out blocks of code

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



From the files of Stupid Keyboard Tricks

Since version 1.0 VB lacked a block comment feature that C/C++ programmers love so dearly.  Finally in version 5, the mothership provided us with half of the solution - one could now go to the Customize menu and add the Comment Block and Uncomment Block button to the toolbar or the menu.  And that was good.  But if you are a keyboard jockey like us, you want something faster and preferably something faster than the /*...*/ operator in C/C++.  This is the story of how to do it:

  1. Right click on the toolbar and select Customize... menu
  2. Under Categories click on Edit, then select Comment Block in the Commands listbox.
  3. Now drag the Comment Block entry onto the Menu Bar (yep! the menu bar)
  4. You should now see a new icon on the menu bar. 
  5. Make sure that the new icon is highlighted (it will have a black square around it) and click Modify Selection button on the Customize dialog box.
  6. An interesting menu will popup.  Under name, add an ampersand to the beginning of the entry.  So now instead of Comment Block it should read &Comment Block.  Press Enter to record the change.
  7. Click on the Modify Selection button once again and select Image and Text.
  8. Dismiss the Customize dialog box.
  9. Now highlight any block of code and press Alt-C.  Voila.
  10. Do the same thing for the Uncomment Block or any other commands that you find yourself using often.

ToolbarEditor With Commented Out Block

 


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/7/2006 10:41:02 AM
this is stupid

#2. By Anonymous. Posted on 3/8/2006 7:54:35 AM
Reply to #1. Stupid or not, it gets the job done. I've been using this since VB6, into VS.NET 2002, 2003 and 2005. There isn't a faster way to uncomment stuff.

#3. By Anonymous. Posted on 5/12/2006 4:23:23 PM
Wonder who the Hack is that said this is stupid?? Obviously someone too stupid to know better. Works great thanks for the tip.

#4. By Anonymous. Posted on 7/4/2006 4:26:45 AM
it helps. it's better than nothing.

#5. By ghh3rd. Posted on 8/9/2006 9:15:17 PM
Glad I stumbled onto this. I found that there's already a button on the Excel VBA toolbar to do this that I wasn't aware of. No more waking up my co-workers with my repetitive clicking while I'm commenting or uncommenting many rows of code.

Granville

#6. By Mimo. Posted on 11/23/2006 1:40:08 AM
a real jockey u r
many thanks 4 u

#7. By Anonymous. Posted on 12/15/2006 6:50:51 AM
Thanks a lot, this really helps when it comes to testing different methods of code :D

#8. By Anonymous. Posted on 1/5/2007 6:02:45 AM
Nice tip, not just for comment/uncomment but also for customizing shortcuts to other actions. Thanks!

#9. By Peter. Posted on 2/2/2007 5:54:35 PM
Oh, yes!!!

This was the most useful thing I've read all day. I've been in per-line commenting hell for months. The tip on customization and the keyboard shortcut are both just as awesome too. Thanks so much!

#10. By world. Posted on 3/18/2007 2:16:53 AM
hello world http://bcreditused.info http://carloanp.info http://refincarloan.info http://badcredith0melan.info http://creditcard0ffer.info

#11. By Chris. Posted on 6/20/2007 5:30:56 PM
This is great!! I didn't even know that Excel had this feature... I was used to C# easy context-menu comment/uncomment... happy to find this back in Excel! This is a real time saver!

#12. By John. Posted on 9/19/2007 5:48:07 PM
somestrangetextvista

#13. By Anonymous. Posted on 9/26/2007 3:26:22 PM
Quote:
#1. By Anonymous. Posted on 3/7/2006 10:41:02 AM
this is stupid
________________________________________________

You're stupid, you probably have no idea what is discussed here...

Robert, GREAT TIP ! Thanks a bunch, really helps!

#14. By Anonymous. Posted on 11/13/2007 9:40:30 AM
There is another to do it:
- insert before the first line to be changed to comment
#If false Then
- insert after the last line to be changed to comment
#End If

#15. By ghh3rd. Posted on 11/13/2007 9:57:55 PM
Hey anonymous...

Thanks for the additional tip to use:

#If false Then
- insert after the last line to be changed to comment
#End If

It works great!

GHH

#16. By g_p_k_. Posted on 12/17/2007 7:46:09 AM
For this tip, I truly love you...

#17. By Anonymous. Posted on 2/19/2008 10:32:45 PM
',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left,',down,left, MAN I WISH I KNEW THIS SOONER HAHAHA

Thanks so much

#18. By Anonymous. Posted on 7/4/2008 10:42:56 AM
fantastic! sped up my copious debugging of the rubbish code I generate no end.

#19. By Anonymous. Posted on 2/4/2009 1:43:42 AM
A: first method is 100% rubbish, too much messing around to obtain simplest result imaginable, I'm sure you're a big fan of Bill Gates too ... ROFL

B: second method better, but still not highlighted in crappy .NET
#If false Then
#End If

C: /* ... */ = ultimate answer leading to conclusion: you people need to start using proper coding languages :D

Question: Why use VB ???

#20. By Anonymous. Posted on 2/4/2009 9:18:34 AM
A: first method is 100% rubbish, too much messing around to obtain simplest result imaginable, I'm sure you're a big fan of Bill Gates too ... ROFL

B: second method better, but still not highlighted in crappy .NET
#If false Then
#End If

C: /* ... */ = ultimate answer leading to conclusion: you people need to start using proper coding languages :D

Question: Why use VB ???

#21. By Anonymous. Posted on 2/4/2009 9:18:47 AM
A: first method is 100% rubbish, too much messing around to obtain simplest result imaginable, I'm sure you're a big fan of Bill Gates too ... ROFL

B: second method better, but still not highlighted in crappy .NET
#If false Then
#End If

C: /* ... */ = ultimate answer leading to conclusion: you people need to start using proper coding languages :D

Question: Why use VB ???

#22. By Anonymous. Posted on 6/10/2009 10:01:48 AM
Typical Microsoft.... bandaid in a feature a few years too late.
how about '/ COMMENT BLOCK /' as something more practical
(at least they made an effort i suppose).

#23. By RealAnon. Posted on 8/14/2009 7:31:55 AM
To the two tools above me: /**/ comment blocks run into issues when you already have a comment block inside. So no system is perfect. Personally, I like setting a key command to comment and uncomment a section of code.

VB is useful when you need to use excel (which if you don't know the uses for, I don't think I could explain it) and/or when you need something done quickly. I love my C++ when I want something exactly how I want it or need something really fast many times. But lets face it, if I want to do some quick accounting or records keeping, vb (and vba) is like writing it out in english and only takes a few minutes, can be shared and edited by many, and takes advantages of all of excel and accesses' features.

Lurk more, troll less. VB has it's place. Assuming you're smarter than everyone does not.
~Dill

#24. By RealAnon. Posted on 8/14/2009 8:12:43 AM
To the two tools above me: /**/ comment blocks run into issues when you already have a comment block inside. So no system is perfect. Personally, I like setting a key command to comment and uncomment a section of code.

VB is useful when you need to use excel (which if you don't know the uses for, I don't think I could explain it) and/or when you need something done quickly. I love my C++ when I want something exactly how I want it or need something really fast many times. But lets face it, if I want to do some quick accounting or records keeping, vb (and vba) is like writing it out in english and only takes a few minutes, can be shared and edited by many, and takes advantages of all of excel and accesses' features.

Lurk more, troll less. VB has it's place. Assuming you're smarter than everyone does not.
~Dill

#25. By RealAnon. Posted on 8/14/2009 4:18:33 PM
To the two tools above me: /**/ comment blocks run into issues when you already have a comment block inside. So no system is perfect. Personally, I like setting a key command to comment and uncomment a section of code.

VB is useful when you need to use excel (which if you don't know the uses for, I don't think I could explain it) and/or when you need something done quickly. I love my C++ when I want something exactly how I want it or need something really fast many times. But lets face it, if I want to do some quick accounting or records keeping, vb (and vba) is like writing it out in english and only takes a few minutes, can be shared and edited by many, and takes advantages of all of excel and accesses' features.

Lurk more, troll less. VB has it's place. Assuming you're smarter than everyone does not.
~Dill

#26. By Kydja. Posted on 8/16/2009 6:39:40 PM
I love u people, do u now that?
Two ways to comment in one minute!!!
I am a better man now!!!!!!!

"Then came a man before His feet he fell
Unclean said the leper and rang his bell
Felt the palm of a hand touch his head
Go now go now you're a new man instead
All going down to see the Lord Jesus
All going down to see the Lord Jesus
All going down"

| |
| HURAAY!!!! |
| |
- -< ---I
8-)- <
- -< ---l

#27. By Teixeira. Posted on 8/28/2009 3:26:32 PM
Great, great!

Most useful thing, great step by step. The tip on customization and the keyboard shortcut are super. Thanks so much!

#28. By Amateur_programmer. Posted on 9/17/2009 7:49:00 PM
thanks so much this just made my life easier!!!
~Florida~

#29. By DJ. Posted on 10/9/2009 12:01:33 AM
I loved this tip. 10 years using VB and I didn't know this.

#30. By Anonymous. Posted on 10/19/2009 5:18:13 AM
thanks bro.....
nice tips~

#31. By Anonymous. Posted on 4/23/2010 9:55:22 AM
Thanks alot mate - truly useful!!

#32. By Anonymous. Posted on 4/23/2010 9:55:27 AM
Thanks alot mate - truly useful!!

#33. By Wylie. Posted on 7/22/2010 11:23:44 PM
Dude, super cool! Thanks for sharing.

#34. By Wylie. Posted on 7/22/2010 11:39:29 PM
Dude, super cool! Thanks for sharing.