Improved AutoIncreasing build number and other macros
Posted
by LJP LJP
on March 19th, 1999
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"), "Text"
Windows(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"), "Text"
Windows(ActiveProject.Name + ".rc").Active = TRUE
ActiveDocument.Save (ActiveProject.Name + ".rc"+"~")
ActiveDocument.Close()
End Sub
Sub restoreRcFile
'DESCRIPTION: Restores back up of rc file.
Documents.Open (ActiveProject.Name + ".rc~"), "Text"
Windows(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, "Text"
End 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 Wnd
' open the project's resource script:
Wnd = ActiveProject.Name + ".rc"
Documents.Open (ActiveProject.Name + ".rc"), "Text"
Windows(ActiveProject.Name + ".rc").Active = True
' SAVE 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 newline - formatted for USA
ActiveDocument.Selection.Text ="// Last compiled "+strMonth+ "/"+strDay +"/"+strYear+" at "+strHour+":"+strMinute+":"+strSecond + vbCrLf
ActiveDocument.Selection.NewLine
' find line with FileVersion Information:
ActiveDocument.Selection.FindText "FILEVERSION", dsMatchForward + dsMatchFromStart + dsMatchCase
' move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine
' mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 'dsExtend does not work in my VisualStudio???
Dim strVersion3
strVersion3 = ActiveDocument.Selection.Text
' Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion3 , strVersion3+1
ActiveDocument.Selection.FindText "PRODUCTVERSION", dsMatchForward + dsMatchFromStart + dsMatchCase
' move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine
' mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 'dsExtend does not work in my VisualStudio???
Dim strVersion4
strVersion4 = ActiveDocument.Selection.Text
' Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion4 , strVersion4+1
ActiveDocument.Selection.FindText "VALUE ""FileVersion"",", dsMatchForward + dsMatchFromStart + dsMatchCase
' move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.CharLeft dsMove, 3
' mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 'dsExtend does not work in my VisualStudio???
Dim strVersion
strVersion = ActiveDocument.Selection.Text
' Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion , strVersion+1
ActiveDocument.Selection.FindText "VALUE ""ProductVersion"",", dsMatchForward + dsMatchFromStart + dsMatchCase
' move to eol and then to end of build number:
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.CharLeft dsMove, 3
' mark Build Number and store in strVersion
ActiveDocument.Selection.WordLeft 1 'dsExtend does not work in my VisualStudio???
Dim strVersion2
strVersion2 = ActiveDocument.Selection.Text
' Increase Version and write back to file:
ActiveDocument.Selection.ReplaceText strVersion2 , strVersion2+1
ActiveDocument.Close()
'build active project
ExecuteCommand "BuildToggleBuild"
Documents.SaveAll True
End Sub

Comments
How can I automatically reload a macro when Opening a project?
Posted by Legacy on 11/17/1999 12:00amOriginally posted by: Karl Brown
ReplyBuild No for dependent projects
Posted by Legacy on 09/22/1999 12:00amOriginally posted by: dashali
How this auto build version numbering can be done for a project which has sub projects as dependencies?
ReplyCorrupts .rc file
Posted by Legacy on 09/15/1999 12:00amOriginally posted by: Peter Cullen
After 6 or 7 builds, I get an error saying that the code_page is invalid. Examining the .rc file in text mode, I can see that the code_page was changed and the dimensions of all of my dialogs were changed! Is there a fix for this?
ReplyDo you have to be in DevStudio to execute macros!?
Posted by Legacy on 03/24/1999 12:00amOriginally posted by: Gary MacDougall
I'd love to be able to do this during my command line build scripts, is it possible to run macros outside of DevStudio using say NMAKE?
Just wondering...
Reply