Jonathan Crossland
Posts: 630
Nickname: jonathanc
Registered: Feb, 2004
|
Jonathan Crossland is a software architect for Lucid Ocean Ltd
|
|
|
|
Macro for ackward turnarounds
|
Posted: Jun 16, 2004 7:46 PM
|
|
Often I find myself writing code like
txtName.Text = someClass.PropertyName;
txtSurname.Text = someClass.PropertySurname;
etc
When you have larger structures and you are busy assigning values to screen or back again, you always end up with copying a block of code and switching it around as in.
someClass.PropertyName = txtName.Text;
someClass.PropertySurname = txtSurname.Text ;
Well a colleague saw that I had a little macro and asked me to put it up. I just remembered today, when I needed it again.
Simply copy the macro sub and paste it into your macros in VS.NET.
Select the text and it turns it around. Makes life a little easier than copying and pasting the values to either side of the = sign.
Public Sub TurnAround()
   Dim selection As TextSelection = DTE.ActiveDocument.Selection()
   Dim codeLines() As String = selection.Text.Split(ControlChars.CrLf)
   Dim codeLine As String
   Dim tmp As String
   For Each codeLine In codeLines
     codeLine = codeLine.Trim()
     Dim part1 As String
     Dim part2 As String
     Dim codeParts() As String = codeLine.Split(Char.Parse("="))
     If codeParts.Length = 2 Then
       part1 = codeParts(1)
       part2 = codeParts(0)
       If part1.EndsWith(";") Then
         part1 = part1.Substring(0, part1.Length - 1)
         part2 += ";"
       End If
       tmp = tmp & part1.Trim() & " = " & part2.Trim() & ControlChars.CrLf
     Else
       tmp = tmp & codeParts(0).Trim() & ControlChars.CrLf
     End If
   Next
   selection.Text = tmp
 End Sub
Read: Macro for ackward turnarounds
|
|