Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incrementing Version Number using VBScript macro in VC++

Status
Not open for further replies.

hne

Programmer
Oct 16, 2003
38
US
I am new to VBScript, however, created a macro that should increment my version number in VC++ every time I compile. I want my macro to skip to the next char when my version count exceeds 9 (i.e. if version is 1.0.0.9, on my next build I would like for it to be 1.0.1.0). I am having problem accomplishing this task can someone help me? PLEASE?!!!! Example of my macro is below...



Sub ReplaceText(selection, count, incrementby)

'selection -- represents the TextSelection object
'count -- represents the position of the version number to be incremented
'incrementby -- represents a number that will be added to the existing version number

Dim str

selection.WordRight dsMove, count
selection.WordRight dsExtend, 1

str = selection.Text
str = str + incrementby

selection.Text = str

End Sub


Sub Application_BuildFinish(numError, numWarning)

'This event will be triggered after every build of a project
'You can check numError and/or numWarning to determine if you want to continue
'If numError <> 0 Then
'exit sub
'Obtain the full path of the active project
Dim full_path
full_path = GetProjectDir(ActiveProject.FullName)

'full_path = full_path & &quot;versionno.h&quot;
full_path = &quot;L:\\certs\\fac\\src\\consolee\\versionno.h&quot;

'Open the VersionNo.h file
Documents.Open full_path

'Obtain the TextSelection object
Dim selection
set selection = ActiveDocument.Selection
selection.StartOfDocument

'Increment the version information
selection.LineDown
ReplaceText selection, 9, 1
selection.LineDown
selection.StartOfLine
ReplaceText selection, 9, 1
selection.LineDown
selection.StartOfLine
ReplaceText selection, 10, 1
selection.LineDown
selection.StartOfLine
ReplaceText selection, 10, 1

ActiveDocument.Save
ActiveDocument.Close

End Sub

 
Try this for incrementing your version.


Ver = &quot;1.0.0.9&quot;

'First strip out the decimals
VerVal = Left(Ver,1) & Mid(Ver,3,1) & Mid(Ver,5,1) & Right(Ver,1)
'Now increment by 1
VerVal = VerVal + 1
'Add back the decimals
Ver = Left(VerVal,1) & &quot;.&quot; & Mid(VerVal,2,1) & &quot;.&quot; & Mid(VerVal,3,1) & &quot;.&quot; & Right(VerVal,1)
'Display the new value
MsgBox Ver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top