Fun with Macros


Author
Message
Charles R Hankey
Charles R Hankey
StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)StrataFrame VIP (1.3K reputation)
Group: Forum Members
Posts: 524, Visits: 30K
In VFP I enjoyed the comment / uncomment right click menu option for blocks of code.  The closest I've been able to find in the VB 2008 IDE is a macro sample to comment and nothing to uncomment.  Soooo, this may be old hat to experienced VS users but if you're a newbie like me you may find this useful :

Tools / Customize / Macros

Now you can drag that Samples.VSEditor.CommentRegion right onto a toolbar.  Then, with the Customize dialog still open, right click on what you dragged onto the bar and select Default Style

Which will reduce it to a blank icon and then pick Chang Button Image to give it an icon.

Okay, now if you hightlight a block of text in code it will all be commented out with single quotes

But what of uncommenting ?

I wrote this macro which you can paste into the macro file that comes up when you open the Macros IDE ( you can drag that out of Tools in customize and onto a menu )

Sub UncommentBlock()

Dim current As String

current = DTE.Activedocument.Name

DTE.ExecuteCommand("Edit.Find")

DTE.ExecuteCommand("Edit.SwitchtoQuickReplace")

DTE.ExecuteCommand("Edit.SelectAll")

DTE.Windows.Item(current).Activate()

DTE.Find.FindWhat = "'"

DTE.Find.ReplaceWith = ""

DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocumentSelection

DTE.Find.MatchCase = False

DTE.Find.MatchWholeWord = False

DTE.Find.MatchInHiddenText = True

DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral

DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone

DTE.Find.Action = vsFindAction.vsFindActionReplaceAll

If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then

Throw New System.Exception("vsFindResultNotFound")

End If

DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close()

End Sub

Just does a search and replace for ' inside a highlighted block

As soon as you save the macro file, you'll find that one the same place you found the CommentRegion() and you can put it on a toolbar the same way.

I'll put the tasklist thing in a separate message.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search