Fun with Macros
 
Home My Account Forum Try It! Buy It!
About Contact Us Site Map
StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Fun with MacrosExpand / Collapse
Author
Message
Posted 04/16/2008 1:31:00 PM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Yesterday @ 6:22:41 PM
Posts: 106, Visits: 392
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.

Post #15697
Posted 04/16/2008 1:35:15 PM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Yesterday @ 6:22:41 PM
Posts: 106, Visits: 392
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

Post #15699
Posted 04/16/2008 11:06:08 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Yesterday @ 6:42:41 PM
Posts: 1,058, Visits: 2,581
Do you know about the keyboard shortcuts?

Highlight the code desired and then
Ctl +k+c to comment
Ctl +k+u to uncomment
Post #15718
Posted 04/17/2008 8:17:52 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 3:24:00 PM
Posts: 3,733, Visits: 3,926
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

Post #15724
Posted 04/17/2008 10:27:02 PM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Yesterday @ 6:22:41 PM
Posts: 106, Visits: 392
Do you know about the keyboard shortcuts?

Obviously no

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

Post #15753
Posted 04/17/2008 10:37:38 PM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: Yesterday @ 6:22:41 PM
Posts: 106, Visits: 392
gotta remember to google !!!

http://blogs.msdn.com/vbteam/archive/2007/04/24/save-time-use-keyboard-shortcuts-lisa-feigenbaum.aspx

http://www.microsoft.com/downloads/details.aspx?FamilyID=6bb41456-9378-4746-b502-b4c5f7182203&DisplayLang=en

Post #15754
Posted 04/18/2008 8:37:56 AM


Advanced StrataFrame User

Advanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame UserAdvanced StrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 4:54:54 PM
Posts: 551, Visits: 10,431
Hey, thanks for the links Charles.
Post #15757
Posted 04/18/2008 12:09:13 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Yesterday @ 6:42:41 PM
Posts: 1,058, Visits: 2,581
Goes along with my life maxim that most of the valuable stuff I know I learned on my way to looking up something else


Ahmen! And I learned a lot about marcos from your example
Post #15764
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.<