Comment Function Macro for C/C++
Posted
by Yevgeniy Marchenko
on October 9th, 2000
- return pointer type with spaces befor "*";
- templates in function parameters
- undefined return
- split function declaration in a few lines
Visual Studio Macro
Sub mcFunctionComments() 'DESCRIPTION: Function comments template 'Author : Y.Marchenko. Date : 23/09/2000 author="Y.Marchenko" Delimeter="::" ' class delimeters a_char=asc("=") ' character used in adornment n_char=60 ' amount of adornment characters used Tab3=vbTab&vbTab&vbTab 'indent 3 tabs Header = Trim(ActiveDocument.Selection) if len(Header)=0 then MsgBox("Select function declaration") Exit Sub end if ActiveDocument.Selection.StartOfLine ActiveDocument.Selection.NewLine ActiveDocument.Selection.LineUp if ActiveDocument.Language <>"C/C++" then ActiveDocument.Selection=ActiveDocument.Language MsgBox("Wrong file type") else 'Delete all comments from function declaration Loc=InStr(Header,"/*") while Loc s1=Left(Header,Loc-1) s2=Mid(Header,InStr(Header,"*/")+2) Header=s1&s2 Loc=InStr(Header,"/*") wend Loc = InStr(Header, "(") f_title=Trim(Left(Header,Loc-1 )) f_pars=Trim(Mid(Header,Loc+1,InStr(Header, ")")-Loc-1)) ActiveDocument.Selection = "/*" + String(n_char,a_char) & "*\" & vbNewLine 'Get the function return type. arrStr=Split(f_title,Delimeter) UB=UBound(arrStr) For i=0 To UB arrStr(i)=Trim(arrStr(i)) Next Loc=InStrRev(arrStr(0)," " ) Loc1=InStrRev(arrStr(0),"*" ) if Loc1>Loc then Loc=Loc1 ' pointer returned f_name=Mid(arrStr(0),Loc+1) f_return=Trim(Left(arrStr(0),Loc)) if Len(f_return) = 0 then ' undefined return type f_return="int (by default)" if UB > 0 then arrStr(UB)=Replace(arrStr(UB)," ","") arrStr(UB)=Replace(arrStr(UB),vbTab,"") if arrStr(UB-1)=arrStr(UB)then f_return="constructor" elseif arrStr(UB) = "~" & arrStr(UB-1) then f_return="destructor" end if end if end if For i=1 To UBound(arrStr) f_name=f_name & Delimeter & Trim(arrStr(i)) Next ActiveDocument.Selection = vbTab & "Author :" & author&Tab3 & "Date : " & Date&Tab3 & "version 1.0" & vbNewLine ActiveDocument.Selection = " " & String(n_char,a_char) & vbNewLine ActiveDocument.Selection = vbTab & "Function :" & Tab3 & f_name & vbNewLine ActiveDocument.Selection = vbTab & "Description :" & vbTab & vbNewLine ActiveDocument.Selection = vbTab & "Return :" & Tab3 & f_return & vbTab & "-" & vbTab & vbNewLine 'Get the function parameters. ActiveDocument.Selection = vbTab & "Parameters :" & vbNewLine arrStr=Split(f_pars,",") bTmpl=false ' template is the current parameter For i=0 To UBound(arrStr) arrStr(i)=Trim(arrStr(i)) Loc = InStr(arrStr(i), "<") if Loc then bTmpl = true if bTmpl then if Loc = 0 then arrStr(i)=arrStr(i-1) & "," & arrStr(i) Loc = InStr(arrStr(i), ">") if Loc then ' template end bTmpl=false ActiveDocument.Selection = Tab3&Replace(arrStr(i),vbNewLine,"") & vbTab & "-" & vbTab&vbNewLine end if end if else ActiveDocument.Selection = Tab3&Replace(arrStr(i),vbNewLine,"") & vbTab & "-" & vbTab&vbNewLine end if Next ActiveDocument.Selection = vbTab & "Note :" & vbNewLine ActiveDocument.Selection = "\*" + String(n_char,a_char) & "*/" end if End Sub

Comments
Online Stopwatch Online Stopwatch Online Stopwatch
Posted by Woficowncix on 03/23/2013 07:01amA Freehttp://www.online-stopwatch.com/ flash online stopwatch, quick easy to use stopwatch! http://www.online-stopwatch.com/also an online countdown! A Free flash online stopwatch, quick easyhttp://www.online-stopwatch.com/ to use stopwatch! also an online countdown! A Free flash online stopwatch, quick easy to use stopwatch! also an online countdown! http://www.online-stopwatch.com/ stopwatch, online stopwatch, online countdown, free online stopwatch, free flash stopwatch, large stopwatch, stopwatch timer, online countdown timer, free countdown timer stopwatch, http://www.online-stopwatch.com/online stopwatch, online countdown, free online stopwatch, http://www.online-stopwatch.com/free flash stopwatch, large stopwatch, stopwatch timer, online countdown timer, free countdown timer stopwatch, online stopwatch, online countdown, free online http://www.online-stopwatch.com/ stopwatch, free flash stopwatch, large stopwatch, stopwatch timer, online countdown timer, free countdown timer
ReplyWorks fine
Posted by Legacy on 05/04/2002 12:00amOriginally posted by: Baelwrath
Copied, rejoined the lines and it works fine.
Remember to edit the author variable and I reduced the tabs and
increased the number of ='s in the boxes, but thats just me!
Good work.
Regards
ReplyTry Failed
Posted by Legacy on 10/24/2001 12:00amOriginally posted by: zimin cai
I have use it but, the only thing it do is that adding a blank line. and before this LOC = Instr(..) bring a error, I comment it. So, I want to know how to use.
ReplyHow to use it ...
Posted by Legacy on 04/29/2001 12:00amOriginally posted by: Yevgeniy Marchenko
Initialy the macro was written correctly.
But when it was publiced here the long strings were devided in short. After that the macro does not work.
If you want to use this macro you need assemble all splited string.
For example:
ActiveDocument.Selection = Tab3&
Replace(arrStr(i),vbNewLine,"")
& vbTab
& "-"
& vbTab&vbNewLine
MUST be:
ActiveDocument.Selection = Tab3&Replace(arrStr(i),vbNewLine,"") & vbTab & "-" & vbTab&vbNewLine
and so on...
Reply