Creating Macros for a Slide-In Prompt and to Renumber

Environment: Developer Studio v6.0, v5.0

When using the Developer Studio IDE, I have always missed some of the functionality I added to my CodeWright environment using a custom .dll I wrote several years back. The two most useful functions I missed most were called SlideInPrompt and Renumber.

The SlideInPrompt macro inserts a text string into a selected column. If only one column was selected, the selected column is left intact and the text inserted at the beginning of the column. If more than one column is selected, the text under the column is deleted before the text is inserted.

The Renumber macro will sequentially renumber a selected column. It will prompt for a beginning number, delete the selected column, and then sequentially ordered numbers are inserted in its place.

The combination of these two macros are great time savers. Here is an example of how you might use them.

Simply select a blank column (hold down your Alt key while selecting, or press CTRL+SHIFT+F8 to go into column mode), and activate the SlideInPrompt macro (I have it tied to CTRL->). Enter your text, such as:

GetDlgItem(IDC_RADIO1)->Enable(FALSE);

You will end up with a column of text like this:

GetDlgItem(IDC_RADIO1)->Enable(FALSE);
GetDlgItem(IDC_RADIO1)->Enable(FALSE);
GetDlgItem(IDC_RADIO1)->Enable(FALSE);
GetDlgItem(IDC_RADIO1)->Enable(FALSE);
GetDlgItem(IDC_RADIO1)->Enable(FALSE);
GetDlgItem(IDC_RADIO1)->Enable(FALSE);

Now comes the renumber macro. Highlight the columns of 1's and active the Renumber macro. It will prompt for a starting number; enter "1" and the column will be renumbered sequentially.

I had to calculate the number of columns selected because I couldn't find a function to return it. Anybody have any ideas on this?

To use this macro, simply highlight it and save it as a .dsm file in the "C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Macros" folder. Select Tools, Customize and go to the Add-Ins and Macros tab. Click the Browse button and select the macro.

'------------------------------------------------------------------
' FILE DESCRIPTION: Two Macros: SlideInPrompt() slides text into
' selection; Renumber() renumbers a column of numbers
' Eric Sanders, February 12, 2001
'------------------------------------------------------------------

Sub SlideInPrompt()
    SlideString = InputBox ("Enter Slide-In string:")
    If SlideString <> "" Then
        SlideIn(SlideString)
    End If
End Sub

Function SlideIn(ByVal SlideString)
    nStartLine = ActiveDocument.Selection.TopLine
    nEndLine = ActiveDocument.Selection.BottomLine

    ' Calculate how many columns have been selected
    ' No direct function to retreive this?
    nChars = len(ActiveDocument.Selection)
    nColumns = ((nChars - 2 * (nEndLine - nStartLine + 1)) _
                            / (nEndLine - nStartLine + 1))

    ' We cut to force cursor to the top left
    ActiveDocument.Selection.Cut

    ' If we only selected one column, then we want the original
    ' text so put it back
    if nColumns = 1 then
        ActiveDocument.Selection.Paste
    end if

    ' Now go through the column adding our string
    nStartColumn = ActiveDocument.Selection.CurrentColumn

    For i = nStartLine To nEndLine
        ActiveDocument.Selection.MoveTo i, nStartColumn
        ActiveDocument.Selection = SlideString
    Next
End Function


Sub Renumber()
    BegNum = InputBox ("Enter beginning number")
    If BegNum <> "" Then
        If IsNumeric(BegNum) Then
            nBegNum = Int(BegNum)
            RenumberColumnSelection(nBegNum)
        End If
    End If
End Sub


Function RenumberColumnSelection (ByVal nBegNum)
    nStartLine = ActiveDocument.Selection.TopLine
    nEndLine = ActiveDocument.Selection.BottomLine
    ActiveDocument.Selection.Delete
    nStartColumn = ActiveDocument.Selection.CurrentColumn

    For i = nStartLine To nEndLine
        ActiveDocument.Selection.MoveTo i, nStartColumn
    ActiveDocument.Selection = nBegNum
    nBegNum = nBegNum + 1
    Next
End Function

Downloads

Source Code (renumber.dsm) - 5kb

September 13, 2002



Comments

  • Promted SlideIn and SlideOut

    Posted by Legacy on 10/24/2002 12:00am

    Originally posted by: Michael

    Hi
    
    

    I also use Codewright at work and miss the PromtedSlideIn
    and PromtedSlideOut functionality which is mostly used to
    comment out large code parts. So I used Eric's base to
    write the two functions:

    Sub PromptedSlideIn()
    SlideString = InputBox ("Enter Slide-In string:")
    If SlideString <> "" Then
    SlideIn(SlideString)
    End If
    End Sub

    Function SlideIn(ByVal SlideString)
    nStartLine = ActiveDocument.Selection.TopLine
    nEndLine = ActiveDocument.Selection.BottomLine

    For i = nStartLine To nEndLine
    ActiveDocument.Selection.MoveTo i, 1
    ActiveDocument.Selection = SlideString
    Next
    End Function

    This works something diffrent from Eric's SlideIn. You can
    select your lines normaly by left mouse and use this macro.
    Beginning at the first column of each line, the string you
    entered is inserted.

    Sub PromtedSlideOut()
    SlideString = InputBox ("Enter Slide-Out string:")
    If SlideString <> "" Then
    SlideOut(SlideString)
    End If
    End Sub

    Function SlideOut(ByVal SlideString)
    nStartLine = ActiveDocument.Selection.TopLine
    nEndLine = ActiveDocument.Selection.BottomLine

    For i = nStartLine To nEndLine
    TmpBlock = ""
    ActiveDocument.Selection.GoToLine i
    ActiveDocument.Selection.SelectLine
    TBX = ActiveDocument.Selection
    if instr(TBX,SlideString) <> 0 then
    TmpBlock = right(TBX, len(TBX) - (instr(TBX, SlideString)_
    + len(SlideString)-1))
    ActiveDocument.Selection = TmpBlock
    end if
    Next
    End Function

    This works with every line, you selected, even, if not full
    selected. It scans the line for the string you entered and,
    if found, delete this string and only this string.

    Reply
  • One additional hint..

    Posted by Legacy on 09/17/2002 12:00am

    Originally posted by: Eric Sanders

    In order to make best use of this macro, you will need to be able to column select an empty column. To do this, you need to have virtual spaces enabled.
    In Visual Studio, select Tools|Options and then the compatibility tab. Make sure that virtual spaces is checked off.

    Regards,
    Eric Sanders
    www.compufoil.com

    Reply
  • Excellent

    Posted by Legacy on 09/16/2002 12:00am

    Originally posted by: Per Nilsson

    Simple and useful.

    Just as a macro should be.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • On-demand Event Event Date: July 22, 2014 In this WhatWorks analysis, John Pescatore examines a use case where end users had local administrative rights on their PCs and it had gotten out of hand for this Fortune 500 Energy and Utilities company. The compelling event that prompted the company to reexamine this situation was the migration to Windows 7. In Windows XP, a custom tool that allowed users one of three levels of administrative rights to their workstations would need to be replaced during the Windows …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds