By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Calculate version number for comparison?

P: n/a
Tom
I have two version numbers - one for my application and another from a
manifest, database, whatever - that isn't important. Now that I have these
two version numbers (in the form major.minor.build.revision) I want to
compare one to see if it is less than the other.

Is there any calculation I can do to convert a version number to a 'real'
number so that I can compare it easily? I've fiddled around with various
methods but nothing works for everything. I have tried to compare the
individual elements one at a time, but there are so many deviations that it
again doesn't work for everything (i.e. 1.9.9.0 is higher than 1.9.8.920).

There seems like there should be some mathematical way to convert this to
some kind of number so my code could simply say something like "if
current_converted_version < new_converted_version then ...'.

Anyone good mathematicians out there?? :-)

Tom
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Tom,
If you have two System.Version objects, you can simply use Version.CompareTo
& Version.Equals to compare two versions in VB.NET. If you are using C# then
you can use the overloaded operators to compare Versions.

Dim v1, v2 As System.Version
If v1.CompareTo(v2) < 0 Then
' v1 is less then v2
End If
System.Version v1, v2;
if (v1 < v2)
{
// v1 is less then v2
}

Note in VS.NET 2005 (Whidbey, due out in 2005) the overloaded comparison
operators can be used.

Note there are constructors on System.Version that accepts a string in
major.minor.build.revision format or as 1 to 4 integers.

Be certain to read the help on Version.CompareTo method for some important
tips.

Hope this helps
Jay

"Tom" <to*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I have two version numbers - one for my application and another from a
manifest, database, whatever - that isn't important. Now that I have these two version numbers (in the form major.minor.build.revision) I want to
compare one to see if it is less than the other.

Is there any calculation I can do to convert a version number to a 'real'
number so that I can compare it easily? I've fiddled around with various
methods but nothing works for everything. I have tried to compare the
individual elements one at a time, but there are so many deviations that it again doesn't work for everything (i.e. 1.9.9.0 is higher than 1.9.8.920).

There seems like there should be some mathematical way to convert this to
some kind of number so my code could simply say something like "if
current_converted_version < new_converted_version then ...'.

Anyone good mathematicians out there?? :-)

Tom

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.