The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Macro for ackward turnarounds

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
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
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jonathan Crossland.
Original Post: Macro for ackward turnarounds
Feed Title: Jonathan Crossland Weblog
Feed URL: http://www.jonathancrossland.com/syndication.axd
Feed Description: Design, Frameworks, Patterns and Idioms
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jonathan Crossland
Latest Posts From Jonathan Crossland Weblog

Advertisement


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

Topic: .NET User Group Treffen am 22.06. in Nürnberg Previous Topic   Next Topic Topic: Windows XP SP2 RC2 is available

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use