<!-- Download Links -->
Download source files - 2 Kb
<!-- Main HTML starts here -->
Introduction
Several weeks ago, I started trying to find a way to automatically increment
build numbers on each compile. I found several articles on the subject and some
source code but none of it did exactly what I wanted it to do, so I decided to write
my own incrementer.
Add the code to an existing macro file or, if you don't have an existing macro file,
create one and add one dummy macro so you can access the code snippet.
Application_BeforeBuildStart() is a Visual Studio defined event handler
and although the code is in a macro file, when you select the Tools|Macro menu item,
you won't see it, so you need at least a dummy macro in the file to access the source code.
Note that these code snippets have been subjected to limited testing and
that you use them at your own risk. They work correctly in the test environment,
but you assume all risk for their use. I will not assume any liability whatsoever for
their failure to work correctly in your environment.
Please e-mail any comments, suggestions for improvement, problems, etc. to me.
Sub Application_BeforeBuildStart()
dim oDoc
dim sBuild
dim sRCFile
dim sOne
dim sTwo
dim iSelect
dim lLineNbr
dim bFound
sRCFile = application.activeproject & ".rc"
set oDoc = Documents.Open(sRCFile, "Text")
oDoc.Selection.FindText " FILEVERSION", dsMatchCase
lLineNbr = oDoc.Selection.CurrentLine
sOne = "[0-9]+,[0-9]+,[0-9]+,"
oDoc.Selection.FindText sOne, dsMatchRegExp
if oDoc.Selection.CurrentLine = lLineNbr then
sOne = oDoc.Selection
sTwo = Replace(sOne, ",", ", ")
oDoc.Selection.CharRight
oDoc.Selection.WordRight dsExtend
sBuild = oDoc.Selection + 1
oDoc.Selection = sBuild
else msgbox "Version number 1 not found. Closing without changes."
oDoc.Close dsSaveChangesNo
set oDoc = nothing
exit sub
end if
for iSelect = 2 to 4
if iSelect = 2 then
bFound = oDoc.Selection.FindText(sOne)
else
bFound = oDoc.Selection.FindText(sTwo)
end if
oDoc.Selection.CharRight
oDoc.Selection.WordRight dsExtend
oDoc.Selection = sBuild
if bFound = False then
msgbox "Version number " & iSelect & " not found. Closing without changes."
oDoc.Close dsSaveChangesNo
set oDoc = nothing
exit sub
end if
next
oDoc.Close dsSaveChangesYes
set oDoc = nothing
End Sub