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

More by Author

Must Read