Increment version number in a variable with .1

Hi there.

What would be the best way to increment version number at the end of a variable?

I have "Project Alpha v1" and want it change to "Project Alpha v1.1", "(...) v1.2" etc. etc.

Thanks!

While certainly not the "best".

This is a basic way:
Increment version number.kmmacros (3.6 KB)

If you want to make sure your version number is always a certain number of decimals. ie: v1.00, or whatever, you can explore using the Calculate Token

Additionally, if you want this to work with other base names, you'll have to either modify the regex, or create a regex that is less specific.

3 Likes

Someone beat me, but here's my solution...

Increment Last Number or add .1 Macro (v11.0.3)

Increment Last Number or add .1.kmmacros (3.4 KB)

2 Likes

For my coding projects I have three separate variables for semantic versioning. MAJOR, MINOR and PATCH

Whenever I need to increment any one of those it’s for a specific reason. If I increment MINOR. I zero out PATCH. If I increment MAJOR, I zero out MINOR and PATCH.

I then concat them as:

“v{MAJOR}.{MINOR}.{PATCH}”

Important question -- what's the version number after v1.9? You'll see that the macros above give different answers. I've gone with @Airy's assumption that it will be v1.10

Increment Point Version.kmmacros (4.2 KB)

Image

But mainly a bit of fun doing the calculation inside the "Search and Replace" :wink:

4 Likes

I highly recommend reading that over if you’re considering versioning best practices.

It’s by no means perfect. But it’s at least a good starting point if you don’t already have your own consistent strategy

4 Likes

Potted version of the advice I give our folks, who are mainly concerned with Word docs and the like:

  1. Be consistent: My Document v1.docx
  2. Always include a version number on the very first save -- don't start with My Document.docx because you won't know if you forgot to add, or maybe deleted, the version number
  3. If you think you'll ever make more than 9 versions of any document, zero-pad your version numbers all the time: My Document v01.docx
  4. If you're a sub-versioner, follow the same rules: My Document v01.01.docx
  5. When you've finished and the document is fixed, delete the version number: My Document.docx

The padding means they'll get a "proper" alphanumeric sort on platforms less smart than macOS. And step 5 means the finalised document is always top of the sort order, plus is less likely to trigger "multiple extension" alerts if they email it to someone.

4 Likes

I'm late to the party here, and you've gotten several great and sensible solutions already, but still I'd like to share this little quirk of an approach, all within a single KM text field:

version .1 up.kmmacros (16 KB)

3 Likes

That's cool. Some nice tricks in there. For the record, you can put all that into a single line, like this:

3 Likes

Very cool!! Thanks so much!