Sub Application_BeforeBuildStart()
' written 7/11/00 by Curt Blackmon
' e-mail any comments, corrections, etc. to curtblackmon@home.com
' updated versions will be at www.ccbcon.com on the Code Snippets page
' invoked automatically before build starts
' will open the project's *.rc file as text
' will search for the version info
' and will increment the build number
dim oDoc
dim sBuild
dim sRCFile
dim sOne
dim sTwo
dim iSelect
dim lLineNbr
dim bFound
'get the name of the active project's .rc file
sRCFile = application.activeproject & ".rc"
'open *.rc file as text
set oDoc = Documents.Open(sRCFile, "Text")
'position to the correct section of the file
oDoc.Selection.FindText " FILEVERSION", dsMatchCase
'save the line number for the next search
lLineNbr = oDoc.Selection.CurrentLine
'use a regular expression search string for the first version search
sOne = "[0-9]+,[0-9]+,[0-9]+,"
'find the first string
oDoc.Selection.FindText sOne, dsMatchRegExp
if oDoc.Selection.CurrentLine = lLineNbr then
'convert the regular expression to an absolute search string
sOne = oDoc.Selection
'build an absolute search string for the strings with embedded spaces
sTwo = Replace(sOne, ",", ", ")
'move to the build number
oDoc.Selection.CharRight
'select the build number
oDoc.Selection.WordRight dsExtend
'increment the build number
sBuild = oDoc.Selection + 1
'replace the old build number with the new one
oDoc.Selection = sBuild
else 'something went wrong
msgbox "Version number 1 not found. Closing without changes."
oDoc.Close dsSaveChangesNo
set oDoc = nothing
exit sub
end if
'now change the other 3 occurences of the build number
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
'close and save *.rc
oDoc.Close dsSaveChangesYes
set oDoc = nothing
End Sub
评论0