프로그래밍을 하다보면 기계적으로 반복해야 할 일들이 생긴다. 이런 일들로 일일이 타이핑을 한다는 것은 매우 지루하고 따분한 일이다. 그래서 코드을 자동으로 생성하도록 할 필요가 생긴다.
곧 개발환경의 매크로를 이용하거나, Perl과 같은 문자열 처리기를 통하여 코드를 자동처리하도록 한다.
다음의 사이트도 그 중의 하나이다.
http://kimsk99.springnote.com/pages/63531- 미리 지정된 텍스트를 현재 커서위치(실렉트된 것)에 삽입하는 매크로
- 현재 편집중인 파일과 같은 이름이고 확장자만 cpp <-> h 로 바뀐 파일을 열어주는 매크로
http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=51&MAEULNo=20&no=8423&ref=8423- 이름과 날짜를 입력
- 수평 라인 주석을 입력
코드 보기
[code] ' Inserts name and date
Sub Signature()
Dim sel As TextSelection = DTE.ActiveDocument.Selection
sel.Insert("// Seungwoo Oh ")
sel.Insert(Format(Date.Today, "yyyy-MM-dd"))
sel.Insert(".")
End Sub[/code]
[code] Sub InsertHorizontalLine()
Dim lineString = "//----------------------------------------------------------------------------" + vbCrLf
Dim sel As TextSelection = DTE.ActiveDocument().Selection()
sel.Text() = lineString
End Sub [/code]
http://serious-code.net/tc/tag/Visual%20Studio%20Macro- 선택된 라인들에서 중복된 라인들은 삭제하고 나머지를 정렬하기
- 자동으로 getter/setter생성하기
코드 보기
[code]Function Strip(ByVal strLine As String)
If Len(strLine) > 0 Then
nBegin = 1
nEnd = Len(strLine)
For i = 1 To Len(strLine)
c = Mid(strLine, i, 1)
If c <> " " And c <> Tab And c <> Lf And c <> Cr Then
nBegin = i
Exit For
End If
Next
For i = 1 To Len(strLine)
c = Mid(strLine, Len(strLine) - i + 1, 1)
If c <> " " And c <> Tab And c <> Lf And c <> Cr Then
nEnd = Len(strLine) - i + 1
Exit For
End If
Next
Return Mid(strLine, nBegin, nEnd - nBegin + 1)
Else
Return ""
End If
End Function[/code]
[code]Sub SortCollection(ByRef oCollection As Collection, Optional ByVal bSortAscending As Boolean = True)
Dim lSort1 As Integer
Dim lSort2 As Integer
Dim vTempItem1 As Object
Dim vTempItem2 As Object
Dim bSwap As Boolean
For lSort1 = 1 To oCollection.Count - 1
For lSort2 = lSort1 + 1 To oCollection.Count
If bSortAscending Then
If oCollection(lSort1) > oCollection(lSort2) Then
bSwap = True
Else
bSwap = False
End If
Else
If oCollection(lSort1) < oCollection(lSort2) Then
bSwap = True
Else
bSwap = False
End If
End If
If bSwap Then
vTempItem1 = oCollection(lSort1)
vTempItem2 = oCollection(lSort2)
oCollection.Add(vTempItem1, Nothing, lSort2)
oCollection.Add(vTempItem2, Nothing, lSort1)
oCollection.Remove(lSort1 + 1)
oCollection.Remove(lSort2 + 1)
End If
Next
Next
End Sub[/code]
[code]Sub SortAndRemoveDuplicatedLine()
Dim objLines As New Collection
Dim objSel As TextSelection = ActiveDocument().Selection
Dim objRanges As TextRanges = objSel.TextRanges
Dim objStartPt As EditPoint = objRanges.Item(1).StartPoint.CreateEditPoint()
Dim objStream As New StringBuilder
For Each strLine In objSel.Text.Split(Lf)
strLine = Strip(strLine)
If objLines.Contains(strLine) = False Then
objLines.Add(strLine, strLine)
End If
Next
SortCollection(objLines)
For Each strLine In objLines
objStream.AppendLine(strLine)
Next
objSel.Text = ""
objStartPt.Insert(objStream.ToString())
End Sub[/code]
- 속성을 위한 매크로

Private 변수를 Property Procedure로 확장하기
Posted by solarview