Improved AutoIncreasing build number and other macros | CodeGuru

Improved AutoIncreasing build number and other macros

I really love using macros in VC++. They make things highly customizable, like I like them. Not how MS wants me to use it. So, I took the liberty to add to Thomas Mahler’s wonderful macro for increasing build number. I added support for increasing ALL the build numbers avaliable in the .rc file. I […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 19, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

I really love using macros in VC++. They make things highly customizable, like I like them.
Not how MS wants me to use it.

So, I took the liberty to add to Thomas Mahler’s wonderful
macro for increasing build number. I added support for increasing ALL the build numbers
avaliable in the .rc file. I also added backing up the file, because I noticed in certain
situations, it would occasionally change settings and lines other than the build
numbers. So use with caution.

I added putting the current compile date/time
to the 2nd line. I also include here, a couple macros for backing up the current active document,
and restoring the .rc file.


First, the small macros-

Sub CurrentDateTime()DESCRIPTION: Saves current date/time to the rc file, on line 2.
    Dim strMonth
    Dim strDay
    Dim strYear
    Dim strHour
    Dim strMinute
    Dim strSecond
	Documents.Open (ActiveProject.Name +.rc),TextWindows(ActiveProject.Name +.rc).Active = TRUE
	ActiveDocument.Selection.GoToLine 2
	ActiveDocument.Selection.SelectLine
	ActiveDocument.Selection.Delete
	strMonth = CStr(DatePart(m, Now))
	strDay = CStr(DatePArt(d, Now))
	strYear = CStr(DatePart(yyyy, Now))
	strHour = CStr(DatePart(h, Now))
	strMinute = CStr(DatePArt(n, Now))
	strSecond = CStr(DatePart(s, Now))
	ActiveDocument.Selection.Text =// Last compiled+strMonth +/+strDay +/+strYear+at+ strHour+:+strMinute+:+strSecond+    + vbCrLf
	ActiveDocument.Selection.NewLine
	ActiveDocument.Save (ActiveProject.Name +.rc)
	ActiveDocument.Close()
End Sub
Sub saveBackUpRC()DESCRIPTION: Backs up rc file.
    Documents.Open (ActiveProject.Name +.rc),TextWindows(ActiveProject.Name +.rc).Active = TRUE
    ActiveDocument.Save (ActiveProject.Name +.rc+~)
    ActiveDocument.Close()
End Sub
Sub restoreRcFileDESCRIPTION: Restores back up of rc file.
    Documents.Open (ActiveProject.Name +.rc~),TextWindows(ActiveProject.Name +.rc~).Active = TRUE
    ActiveDocument.Save (ActiveProject.Name +.rc)
    ActiveDocument.Close()
End Sub
Sub saveActiveDocBackup()DESCRIPTION: Backs up current active document.
    Dim Wnd
    Wnd = ActiveDocument.FullName
    ActiveDocument.Save(ActiveDocument.fullname +~)
    ActiveDocument.Close()
    Documents.Open Wnd,TextEnd Sub

Now, the improved build increase macro


Sub IncResVersion()DESCRIPTION: Build active project and increase version counters in rc script.Map it to F7 for ease of use. (c)98 Th. Mahler and parts by LJP.
    Dim strMonth
    Dim strDay
    Dim strYear
    Dim strHour
    Dim strMinute
    Dim strSecond
	Dim Wndopen the projects resource script:
	Wnd = ActiveProject.Name +.rcDocuments.Open (ActiveProject.Name +.rc),TextWindows(ActiveProject.Name +.rc).Active = TrueSAVE BACK-UP OF FILE >>>>
	ActiveDocument.Save (ActiveProject.Name +.rc+~)
	ActiveDocument.Close()
	Documents.Open Wnd,Text”
	‘Go to 2nd line in rc file, delete it, and get current time/date
	ActiveDocument.Selection.GoToLine 2
	ActiveDocument.Selection.SelectLine
	ActiveDocument.Selection.Delete
	strMonth = CStr(DatePart(m, Now))
	strDay = CStr(DatePArt(d, Now))
	strYear = CStr(DatePart(yyyy, Now))
	strHour = CStr(DatePart(h, Now))
	strMinute = CStr(DatePArt(n, Now))
	strSecond = CStr(DatePart(s, Now))write current date/time and add newlineformatted for USA
	ActiveDocument.Selection.Text =// Last compiled+strMonth+/+strDay +/+strYear+at+strHour+:+strMinute+:+strSecond    + vbCrLf
	ActiveDocument.Selection.NewLinefind line with FileVersion Information:
	ActiveDocument.Selection.FindTextFILEVERSION, dsMatchForward + dsMatchFromStart + dsMatchCasemove to eol and then to end of build number:
	ActiveDocument.Selection.EndOfLinemark Build Number and store in strVersion
	ActiveDocument.Selection.WordLeft 1dsExtend does not work in my VisualStudio???
	Dim strVersion3
	strVersion3 = ActiveDocument.Selection.TextIncrease Version and write back to file:
	ActiveDocument.Selection.ReplaceText strVersion3 , strVersion3+1
	ActiveDocument.Selection.FindTextPRODUCTVERSION, dsMatchForward + dsMatchFromStart + dsMatchCasemove to eol and then to end of build number:
	ActiveDocument.Selection.EndOfLinemark Build Number and store in strVersion
	ActiveDocument.Selection.WordLeft 1dsExtend does not work in my VisualStudio???
	Dim strVersion4
	strVersion4 = ActiveDocument.Selection.TextIncrease Version and write back to file:
	ActiveDocument.Selection.ReplaceText strVersion4 , strVersion4+1
	ActiveDocument.Selection.FindTextVALUE “”FileVersion””,, dsMatchForward + dsMatchFromStart + dsMatchCasemove to eol and then to end of build number:
	ActiveDocument.Selection.EndOfLine
	ActiveDocument.Selection.CharLeft dsMove, 3mark Build Number and store in strVersion
	ActiveDocument.Selection.WordLeft 1dsExtend does not work in my VisualStudio???
	Dim strVersion
	strVersion = ActiveDocument.Selection.TextIncrease Version and write back to file:
	ActiveDocument.Selection.ReplaceText strVersion , strVersion+1
	ActiveDocument.Selection.FindTextVALUE “”ProductVersion””,, dsMatchForward + dsMatchFromStart + dsMatchCasemove to eol and then to end of build number:
	ActiveDocument.Selection.EndOfLine
	ActiveDocument.Selection.CharLeft dsMove, 3mark Build Number and store in strVersion
	ActiveDocument.Selection.WordLeft 1dsExtend does not work in my VisualStudio???
	Dim strVersion2
	strVersion2 = ActiveDocument.Selection.TextIncrease Version and write back to file:
	ActiveDocument.Selection.ReplaceText strVersion2 , strVersion2+1
	ActiveDocument.Close()build active project
	ExecuteCommandBuildToggleBuildDocuments.SaveAll True
End Sub

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.