Click here to Skip to main content
15,884,176 members
Articles / Programming Languages / C++
Article

An Automatic Build Incrementer for VC6

Rate me:
Please Sign up or sign in to vote.
3.77/5 (6 votes)
11 Jul 2000 86.4K   445   24   14
An article on how to add an automatic build incrementer to VC6
  • Download source files - 2 Kb
  • 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()
       ' 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


    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    Web Developer
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    Generalanother improvement Pin
    gok16-Apr-04 12:10
    professionalgok16-Apr-04 12:10 
    Great macro. Thanks!
    Some applications are called from inside other frames (dll). To get dll version I'm using extra string in string table called "IDS_FILEVERSION" synchronizing with Version section like that:

    ...
    'replace the old build number with the new one
    oDoc.Selection = sBuild

    '-----------------------------------------------------------
    'gok: replace in string table as well
    oDoc.Selection.FindText "IDS_FILEVERSION", dsMatchCase
    oDoc.Selection.WordRight dsMove, 8 'skip spaces, quote, 3 numbers
    oDoc.Selection.WordRight dsExtend, 1 'seat on build number
    oDoc.Selection = sBuild
    '-----------------------------------------------------------
    ...

    Wink | ;)


    Gennady Khokhorin
    Software Developer
    GeneralA small problem Pin
    Charles Sicotte25-Dec-00 11:13
    Charles Sicotte25-Dec-00 11:13 
    GeneralNice macro, but... Pin
    _stefanu_18-Jul-00 3:32
    _stefanu_18-Jul-00 3:32 
    GeneralRe: Nice macro, but... Pin
    ArchieSEB18-Jul-00 4:09
    sussArchieSEB18-Jul-00 4:09 
    GeneralRe: Nice macro, but... Pin
    Rubke16-Jul-01 2:08
    Rubke16-Jul-01 2:08 
    GeneralAdditional Instructions for VS macro newbies Pin
    CousinBug17-Jul-00 15:10
    CousinBug17-Jul-00 15:10 
    GeneralWorks fine, I tried some of the others , this one seems easiest Pin
    JCardinal17-Jul-00 11:23
    sussJCardinal17-Jul-00 11:23 
    GeneralDebug build Pin
    Jens Kreiensiek16-Jul-00 21:06
    Jens Kreiensiek16-Jul-00 21:06 
    GeneralRe: Debug build Pin
    Edgar R. C.1-Oct-03 15:07
    Edgar R. C.1-Oct-03 15:07 
    GeneralRe: Debug build Pin
    Edgar R. C.1-Oct-03 17:03
    Edgar R. C.1-Oct-03 17:03 
    GeneralBug and fix! Pin
    Fredrik Tonn13-Jul-00 7:33
    sussFredrik Tonn13-Jul-00 7:33 
    GeneralRe: Bug and fix! Pin
    Curt Blackmon13-Jul-00 11:51
    Curt Blackmon13-Jul-00 11:51 
    GeneralRe: Bug and fix! Pin
    James27-Oct-00 1:44
    James27-Oct-00 1:44 
    GeneralRe: Bug and fix! Pin
    flo027-Jan-03 22:25
    flo027-Jan-03 22:25 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.