Macros coming from VS2003 not working right in VS2005

N

n4ixt

I have two macros I used to use in VS 2003. I recently tried to import them
for use in VS 2005, but they don't seem to work. I open the macro explorer,
right click and do run, but it's like VS never calls the things. What the
heck am I doing wrong?

Maybe it's just the late hour but I've been going in circles trying to
figure it out. Here's the entire macro module below (be on the look out in
case of any word wrap), any help is appreciated. And if you find 'em useful
(once they are fixed) help yourself. The only change I made for VS2005 was
the addition of the Imports EnvDTE80 line, thinking there may be some
overrides I need, but that didn't seem to fix it.

Thanks,

Robert

Imports EnvDTE
Imports EnvDTE80

Imports System.Diagnostics

Imports System.Text

Imports Microsoft.VisualBasic

Public Module N4IXT

Sub InsertPropertyXMLComments()

'Note: You must go into Tools, Options, Text Editor, C#, Formatting and

'UNCHECK the "Smart Comment Editing" feature or else this entire property

'will wind up in a /// <summary> </summary> block.

Dim vbcrlf As String = Microsoft.VisualBasic.Constants.vbCrLf

Dim ts As TextSelection = DTE.ActiveDocument.Selection

ts.SelectLine()

Dim propline As String = ts.Text.Trim()

If propline.Length = 0 Then

MsgBox("You must enter a string in the form of " + vbcrlf _

+ " scope datatype propertyname" + vbcrlf _

+ "in order to run this macro. Example: public string FirstName",
MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error Inserting Property")

Exit Sub

End If

Dim props() As String = Split(propline)

If props.Length <> 3 Then

MsgBox("You must enter a string in the form of " + vbcrlf _

+ " scope datatype propertyname" + vbcrlf _

+ "in order to run this macro. Example: public string FirstName",
MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error Inserting Property")

Exit Sub

End If

Dim propname As String = props(2)

Dim proptype As String = props(1)

Dim propscope As String = props(0)

Dim instext As StringBuilder = New StringBuilder

instext.Append("
///************************************************************************"
+ vbcrlf)

instext.Append(" /// <summary>" + vbcrlf)

instext.Append(" /// " + propname + vbcrlf)

instext.Append(" /// </summary>" + vbcrlf)

instext.Append(" /// <returns>" + vbcrlf)

instext.Append(" /// The property " + propname + " returns a data type of "
+ proptype + "." + vbcrlf)

instext.Append(" /// </returns>" + vbcrlf)

instext.Append(" /// <revisionhistory>" + vbcrlf)

instext.Append(" /// " + Now.Today.ToString() + " - Robert C. Cain -
Created." + vbcrlf)

instext.Append(" /// </revisionhistory>" + vbcrlf)

instext.Append("
///************************************************************************"
+ vbcrlf)

instext.Append(" " + propscope + " " + proptype + " " + propname + vbcrlf)

instext.Append(" {" + vbcrlf)

instext.Append(" get" + vbcrlf)

instext.Append(" {" + vbcrlf)

instext.Append(" return _" + propname + ";" + vbcrlf)

instext.Append(" }" + vbcrlf)

instext.Append(" set" + vbcrlf)

instext.Append(" {" + vbcrlf)

instext.Append(" _" + propname + " = value;" + vbcrlf)

instext.Append(" }" + vbcrlf)

instext.Append(" }" + vbcrlf)

instext.Append(vbcrlf)

Dim inserttext As String = instext.ToString()

ts.Insert(inserttext)

'This little dance will clear the selection and put the cursor at the end of
the procedure line

ts.EndOfLine()

ts.LineUp()

ts.EndOfLine()

End Sub

Sub DocProcXML()

Dim vbcrlf As String = Microsoft.VisualBasic.Constants.vbCrLf

Dim ts As TextSelection = DTE.ActiveDocument.Selection()

ts.SelectLine()

Dim origprocline As String = ts.Text

Dim procline As String = ts.Text.Trim()

'First get the method name, scope, and datatype

Dim LeftParenPos = procline.IndexOf("(")

If LeftParenPos < 1 Then

MsgBox("Not a valid declaration.", MsgBoxStyle.Critical, "Document
Procedure")

Exit Sub

End If

Dim ProcInfo As String = procline.Substring(0, LeftParenPos)

Dim ProcVars As String = procline.Substring(LeftParenPos + 1)

Dim RightParenPos As Integer = ProcVars.IndexOf(")")

If RightParenPos < 0 Then

MsgBox("This macro currently supports only declarations that are on a single
line. Please " _

+ "put the entire procedure definition on one line then run again.",
MsgBoxStyle.Critical, "Document Procedure Standard Comments(")")

Exit Sub

End If

ProcVars = ProcVars.Substring(0, RightParenPos)

Dim ProcInfos() As String = ProcInfo.Trim().Split(" ")

Dim procscope = ProcInfos(0)

Dim procdatatype = ProcInfos(1)

Dim procname = ProcInfos(2)

Dim instext As StringBuilder = New StringBuilder

instext.Append("
///************************************************************************"
+ vbcrlf)

instext.Append(" /// <summary>" + vbcrlf)

instext.Append(" /// " + procname + vbcrlf)

instext.Append(" /// </summary>" + vbcrlf)

instext.Append(" /// <returns> " + vbcrlf)

instext.Append(" /// The method " + procname + " returns a data type of " +
procdatatype + "." + vbcrlf)

instext.Append(" /// </returns> " + vbcrlf)

If ProcVars.Length > 0 Then

Dim vars() As String = ProcVars.Split(",")

Dim var As String

For Each var In vars

instext.Append(" /// <param name=" + Chr(34))

Dim varparts() As String = var.Trim().Split(" ")

instext.Append(varparts(1) + Chr(34) + ">")

instext.Append(varparts(1) + " a variable of type " + varparts(0) +
"</param>" + vbcrlf)

Next

End If



instext.Append(" /// <revisionhistory>" + vbcrlf)

instext.Append(" /// " + Now.ToString() + " - Robert C. Cain - Created." +
vbcrlf)

instext.Append(" /// </revisionhistory>" + vbcrlf)

instext.Append("
///************************************************************************"
+ vbcrlf)

Dim inserttext As String = instext.ToString()

ts.Insert(inserttext, vsInsertFlags.vsInsertFlagsInsertAtStart)

'This little dance will clear the selection and put the cursor at the end of
the procedure line

ts.EndOfLine()

ts.LineUp()

ts.EndOfLine()

End Sub



End Module
 
N

n4ixt

Oops, found it.

Right after sending this, it occurred to me I really outta unload then
reload visual studio. I did, then it seemed to run the macros, and of course
pointed out my error, namely that this line:
MsgBox("This macro currently supports only declarations that are on a
single line. Please " _
+ "put the entire procedure definition on one line then run again.",
MsgBoxStyle.Critical, "Document Procedure Standard Comments(")")

Really should not end like that, but rather
+ "put the entire procedure definition on one line then run again.",
MsgBoxStyle.Critical, "Document Procedure Standard Comments")

Live and learn.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top