Fun with Macros


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 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.

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
And here's the comment / task list token macro :

'And you can customize this even further by using YOUR initials instead of mine :-)

Sub InsertCRH()

Dim textSelection As EnvDTE.TextSelection

textSelection = CType(DTE.Activedocument.Selection(), EnvDTE.TextSelection)

textSelection.Text = "' CRH: " & System.DateTime.Now.ToString() & CrLf _

& "' "

End Sub

See prior message for putting it on a toolbar and my message about snippets in General .NET section to see about the method and reasons to put your initials into a task list token

Charles

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.7K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Do you know about the keyboard shortcuts?



Highlight the code desired and then

Ctl +k+c to comment

Ctl +k+u to uncomment
Trent Taylor
Trent Taylor
StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Do you know about the keyboard shortcuts?

Highlight the code desired and then
Ctl +k+c to comment
Ctl +k+u to uncomment

Very close and personal friends BigGrin

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Do you know about the keyboard shortcuts?

Obviously no Blush

Seemed like there should be something like that but darned if I could find them ( where shoulld I have been looking to find a list of such shortcuts? )

Oh well, learned a lot of cool stuff about macros along the way. 

Goes along with my life maxim that most of the valuable stuff I know I learned on my way to looking up something else Smile

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)Advanced StrataFrame User (764 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)Strategic Support Team Member (2.8K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hey, thanks for the links Charles. Wink
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.7K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Goes along with my life maxim that most of the valuable stuff I know I learned on my way to looking up something else Smile




Ahmen! And I learned a lot about marcos from your example BigGrin
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