Sequentially Renumber resource ID's

This macro will take a selection and renumber the resource ID's in sequential order. This comes in very handy when trying to avoid resource conflicts as well as when trying to merge items from one resouce file into another.

' This will assisgn resource ID's to the selected block by starting 
' with the resource ID given and then incrementing until the end of 
' the selection is reaced.
' (Uncomment the commented lines to process only sourcecode files)

Sub AssignResourceIDToSelection ()

     msg = InputBox ("Enter The resource ID to start From:")

'    TypeOfFile = FileType(ActiveDocument)

'    if TypeOfFile <> dsCPP   Then
'         MsgBox "File Must be of type .c, .cpp, .cxx, .h, .hpp, .hxx"
'    Else
          If msg <> "" Then
               If IsNumeric(msg) Then
                    nCurResourceID = Int(msg)
                    AssignGivenResourceIDToSelection(nCurResourceID)
               End If
          Else
               MsgBox "You MUST enter a resource ID, Aborting"
          End If
'    End if
End Sub


'This function can be integrated with other macros to
'automate the renumbering of resource ID's

Function AssignGivenResourceIDToSelection (ByVal nCurResourceID)

     nStartLine = ActiveDocument.Selection.TopLine
     nEndLine = ActiveDocument.Selection.BottomLine

     ' Debugging messageBox
     ' MsgBox "Start:" + CStr(nStartLine) + " End:" + + CStr(nEndLine)
     For i = nStartLine To nEndLine
          ActiveDocument.Selection.GoToLine i
          ActiveDocument.Selection.FindText "#define", dsMatchForward
          If ActiveDocument.Selection.CurrentLine = i Then
               ' Debugging messageBox
               ' MsgBox "Ext:" + CStr(ActiveDocument.Selection.CurrentLine)
               ActiveDocument.Selection.EndOfLine
               ActiveDocument.Selection.WordLeft dsExtend
               ActiveDocument.Selection = nCurResourceID
               nCurResourceID = nCurResourceID + 1
          End if
     Next

End Function

Updated 21 March 1998



Comments

  • *** IT'S GREAT ***

    Posted by Legacy on 04/15/2003 12:00am

    Originally posted by: Tom

    I frequently add or remove the resources. So its very useful to me.

    Reply
  • ID Resequencing with MSDev 7 (2002)

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

    Originally posted by: Niklas

    Imports EnvDTE
    
    Imports System.Diagnostics

    Public Module Resquence

    Sub ResequenceSelection()

    Dim szMsg As String
    Dim nCurResourceID As Integer
    szMsg = InputBox("Enter The resource ID to start From:")

    If szMsg <> "" Then
    If IsNumeric(szMsg) Then
    nCurResourceID = Int(szMsg)
    ResequenceSelectionFromID(nCurResourceID)
    End If
    Else
    MsgBox("ABORT: No Resourse ID")
    End If
    End Sub

    Function ResequenceSelectionFromID(ByVal nCurResourceID)

    Dim tsSel As TextSelection = DTE.ActiveDocument.Selection
    Dim epOrigAnchor As EditPoint = tsSel.AnchorPoint.CreateEditPoint
    Dim epOrigActive As EditPoint = tsSel.ActivePoint.CreateEditPoint
    Dim epWork As EditPoint
    Dim tpEndOfLine As TextPoint

    tsSel.MoveToPoint(epOrigAnchor)
    While (tsSel.FindText("#define") And tsSel.AnchorPoint.LessThan(epOrigActive))
    epWork = tsSel.ActivePoint.CreateEditPoint()
    tpEndOfLine = epWork.CreateEditPoint()
    tpEndOfLine.EndOfLine()
    epWork.EndOfLine()
    epWork.WordLeft()
    epWork.Delete(tpEndOfLine)
    epWork.Insert(nCurResourceID)
    nCurResourceID = nCurResourceID + 1
    End While

    tsSel.MoveToPoint(epOrigAnchor)
    tsSel.MoveToPoint(epOrigActive, True)

    End Function
    End Module

    Reply
  • Wish I had this last week!

    Posted by Legacy on 12/21/2001 12:00am

    Originally posted by: Mike Niday

    Great Macro!
    :-)

    Reply
  • My solve: Sequentially Renumber Resource ID's

    Posted by Legacy on 08/09/2001 12:00am

    Originally posted by: Tran Thai Nhan

    Sub MakeSelectedIDNicer()
    
    'DESCRIPTION: Sequentially Renumber Resource ID's
    'Written by Tran Thai Nhan

    ' Check that the current document can be changed
    if ActiveDocument.ReadOnly then
    MsgBox "This macro cannot be executed on a read-only file.", _
    vbExclamation
    end if

    ' Save current line so we can return to it at the end
    dim nCurLine, StartLine, EndLine
    nCurLine = ActiveDocument.Selection.CurrentLine
    StartLine = ActiveDocument.Selection.TopLine
    EndLine = ActiveDocument.Selection.BottomLine

    If StartLine > EndLine Then
    temp = StartLine
    StartLine = EndLine
    EndLine = temp
    end if

    If EndLine > StartLine Then
    ActiveDocument.Selection.GoToLine StartLine
    ActiveDocument.Selection.StartOfLine
    ActiveDocument.Selection.StartOfLine
    ActiveDocument.Selection.WordRight dsMove, 3
    ActiveDocument.Selection.WordRight dsExtend
    dim num
    num = int (ActiveDocument.Selection)

    while ActiveDocument.Selection.CurrentLine <= EndLine
    ActiveDocument.Selection = num
    ActiveDocument.Selection.LineDown
    ActiveDocument.Selection.StartOfLine
    ActiveDocument.Selection.StartOfLine
    ActiveDocument.Selection.WordRight dsMove, 3
    ActiveDocument.Selection.WordRight dsExtend
    num = num + 1
    wend
    End if

    ' Go back to where we were at the beginning
    ActiveDocument.Selection.GoToLine nCurLine
    End Sub

    Reply
  • Great Macro!! Here is a tiny improvement

    Posted by Legacy on 07/29/1999 12:00am

    Originally posted by: Ilia Malamoud

    If in the function
    AssignGivenResourceIDToSelection

    change the following part

    If ActiveDocument.Selection.CurrentLine = i Then
    ' Debugging messageBox
    ' MsgBox "Ext:" + CStr(ActiveDocument.Selection.CurrentLine)
    ActiveDocument.Selection.EndOfLine
    ActiveDocument.Selection.WordLeft dsExtend
    ActiveDocument.Selection = nCurResourceID
    nCurResourceID = nCurResourceID + 1
    End if

    to the following


    If ActiveDocument.Selection.CurrentLine = i Then
    ' Debugging messageBox
    ' MsgBox "Ext:" + CStr(ActiveDocument.Selection.CurrentLine)
    ActiveDocument.Selection.StartOfLine
    ActiveDocument.Selection.WordRight dsMove
    ActiveDocument.Selection.WordRight dsMove
    ActiveDocument.Selection.WordRight dsMove
    ActiveDocument.Selection.WordRight dsExtend
    ActiveDocument.Selection = nCurResourceID
    ActiveDocument.Selection = ActiveDocument.Selection + " "
    nCurResourceID = nCurResourceID + 1
    End if


    it will fix the renumbering of the "defines" commented on the right like this:

    #define DS_ALLOC 180 // Id of the button
    #define DS_DEFAULT 181 // Defaults the base
    #define DS_GROUP 183 // String Id

    Reply
  • Great macro - add fix for internation users

    Posted by Legacy on 02/02/1999 12:00am

    Originally posted by: Hanspeter Gysin

    This is a very usefull macro when one merges or splits projects.

    I first tried the macro and the previous resource ids are moved to right and not overwritten.
    This is based on a BUG in Visual Studio 5.0 (see article Q183813).
    The constants are not defined for language settings different to "English (U.S)"

    FIX:
    set dsExtend = 1 in the Function "AssignGivenResourceIDToSelection" and the resource ids will be overwitten (dsMove = 0, undefined macros are zero or blank)

    Hanspeter Gysin

    Reply
  • Can't live without this !

    Posted by Legacy on 01/12/1999 12:00am

    Originally posted by: Hans Wedemeyer

    Super, what a timer saver... Thanks.

    regards
    Hans Wedemeyer

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

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • The hard facts on SaaS adoption in over 80,000 enterprises: Public vs. private companies Mid-market vs. large enterprise GoogleApps, Office365, Salesforce & more Why security is a growing concern Fill out the form to download the full cloud adoption report.

Most Popular Programming Stories

More for Developers

RSS Feeds