The Code Project View our sponsorsClick here for Dundas Consulting - experts in MFC, C++, TCP/IP and ASPAdvertise on the CodeProject
Home >> Macros and Add-ins >> Macros

An Automatic Build Incrementer for VC6
By Curt Blackmon

An article on how to add an automatic build incrementer to VC6 
 VC6
 Posted 12 Jul 2000
Articles by this author
Send to a friend
Printer friendly version
Home Latest updates Submit your article About Us Advertise on the Code Project Contact us Discussion Forums
Navigation bar
18 users have rated this article. result:
4.39 out of 5.
  • 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
    


    [Top] Sign in to vote for this article:     PoorExcellent  

    View our sponsorsClick here for Dundas Software's TCP/IP Development KitAdvertise on the CodeProject

    Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
     Keyword Filter
     View   Per page   Messages since
    New threadMessages 1 to 10 of 10 (Total: 10)[First] [Prev] [Next] [Last]
    Subject 
    Author 
    Date 
      A small problem
     Charles Sicotte 17:13 25 Dec 00 
      Nice macro, but...
    Unconfirmed/Anonymous posting Steve 9:32 18 Jul 00 
      Re: Nice macro, but...
    Unconfirmed/Anonymous posting ArchieSEB 10:09 18 Jul 00 
      Re: Nice macro, but...
     Rubke 8:08 16 Jul 01 
      Additional Instructions for VS macro newbies
    Unconfirmed/Anonymous posting Ricky Faulstich 21:10 17 Jul 00 
      Works fine, I tried some of the others , this one seems easiest
    Unconfirmed/Anonymous posting JCardinal 17:23 17 Jul 00 
      Debug build
    Unconfirmed/Anonymous posting Jens Kreiensiek 3:06 17 Jul 00 
      Bug and fix!
    Unconfirmed/Anonymous posting Fredrik Tonn 13:33 13 Jul 00 
      Re: Bug and fix!
    Unconfirmed/Anonymous posting Curt Blackmon 17:51 13 Jul 00 
      Re: Bug and fix!
    Unconfirmed/Anonymous posting James 7:44 27 Oct 00 
    Last Visit: 12:00 Friday 1st January, 1999[First] [Prev] [Next] [Last]
    Home >> Macros and Add-ins >> Macros
    Advertise on The Code Project
    Article content copyright Curt Blackmon, 2000
    everything else © CodeProject, 1999-2001.