Sunday, March 1, 2009

Visual Studio Macros

Hi
Are you aware with power of visual studio macros. It can help you lot in making your coding very much easier.

Here is small snippet which will help you commenting your page when you start creating page, when you are modifying the code or creating region with comments.

Add following code to visual studio macros.

/// For Starting new Page. Once you have added new page. Go to code window and then click on this macro
Sub PageCreateDetails()
DTE.ActiveDocument.Selection.StartofDocument()
DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.Text = "//*****************************Page Deatils*****************************"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//File Name: " + DTE.ActiveDocument.Name
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//Created Date: " + Date.Now
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//Created By: " + InputBox("Enter Your Name")
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//Page Description: " + InputBox("Page Description")
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//*******************************End Page Details***************************"
DTE.ActiveDocument.Selection.EndofDocument()
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.LineUp(False, 1)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//Macro Create Methods ****"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.EndofDocument()
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.LineUp(False, 1)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//Macro Generated Events ****"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.EndofDocument()
DTE.ActiveDocument.Selection.EndofLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.LineDown(False, 2)
DTE.ActiveDocument.Selection.Text = "//***************************Page Modified History*******************************"

End Sub

/// For maintaining details when you modify code.
Sub PageModifyDetails()

DTE.ActiveDocument.Selection.EndofDocument()
DTE.ActiveDocument.Selection.EndofLine()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.Text = "//Modified Date:" + Date.Now
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//Modified By:" + InputBox("Enter Your Name")
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//Details:" + InputBox("Enter Description of changes you have done.")
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "//--------------------------------------------------------"


End Sub

/// For Creating Region. Select your code and click on this macro

Sub CreateRegion()
'Select Area to put in Region and enter region name
Dim sel As EnvDTE.TextSelection
sel = DTE.ActiveWindow.Selection
Dim RegionName As String
Dim sComment As String
RegionName = InputBox("Region Name", "ingenious Macros")
If (MsgBox("Do you want to enter some comments to region", MsgBoxStyle.YesNo)) = MsgBoxResult.Yes Then
sComment = InputBox("Comments Please:")
sel.Text = "#region " + RegionName + vbCrLf + "//" + sComment + vbCrLf + sel.Text + vbCrLf + "#endregion " + RegionName
Else
sel.Text = "#region " + RegionName + vbCrLf + sel.Text + vbCrLf + "#endregion " + RegionName
End If
End Sub

Regards,
Upendra Kolte

No comments:

Post a Comment

Please post your comments on this articles so that I can provide with you information you are looking for and also let me know if you like or dont like this article. Your comments are most welcome.