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

  • On-Demand eSeminar DevOps and Cloud are all the rage in IT, but the two terms relating process and computing aren't mutually exclusive. Join us to see how your movement into cloud changes the way you develop, deploy, test and manage, and how DevOps can actually be a good thing when coupled with cloud.

  • On-demand Event Event Date: May 18, 2015 While the idea of using facial and/or gesture recognition to create a modern, intuitive game seems attractive, some developers may want to leverage Unity 3D as a way to accelerate their development efforts. There are many different ways in which Intel and Unity Technologies have been working together to help speed the development of games with the Intel&reag; RealSense™ SDK (software developer kit). Check out this webcast to join a panel of experts as they …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date