Results 1 to 4 of 4

Thread: [RESOLVED] Comparing versions = Headache

  1. #1

    Thread Starter
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Resolved [RESOLVED] Comparing versions = Headache

    Hi guys,

    In my application I need to compare two versions against each other, but I'm not quite sure how to go on with this. The structure of the versions is like this; Major, Minor, Build, Revison (ex: 1.0.0.0).

    Example:
    So if I compare 1.0.0.10 with 1.3.0.3, I'm thinking that I need to split each version into 4 integers and then compare them with the 4 integers in the other version, but that would require a lot of If's and Then's, wouldn't it?? There is probably a neat way of doing this, but I can't come up with nothing at the moment...

    Any ideas??

    Arve
    Last edited by Arve K.; Jul 25th, 2010 at 07:49 AM.
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem
    Disclaimer: I am not a professional programmer

  2. #2
    Hyperactive Member Zeljko's Avatar
    Join Date
    Oct 2006
    Location
    Internet
    Posts
    441

    Re: Comparing versions = Headache

    You can just use simple comparision between two versions
    VB.Net Code:
    1. Dim v1 As Version = My.Application.Info.Version
    2. Dim v2 As Version = New Version("1.0.0.10")
    3. If v2 > v1 Then
    4.    ' do something
    5. Else
    6.    ' do something
    7. End If
    1. If this post helped you, please Rate it = That's You, saying Thanks, to Me ...Left side of this post: [Rate this post]
    2. Mark this Thread Resolved if your question has been answered That's You, saying Thanks, to Group ...Menu on top of your original Post: [Thread Tools]>[Mark Thread Resolved]
    3.
    Check my site: www.er-ef.netCheck my snippets: Get installed .NET versionsRegex extractingJoin hierarchically nested Datatables in one flattened Datatable


  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Comparing versions = Headache

    You can use the Version class, like so:

    Code:
    Dim Version1 As New Version("1.0.2.4")
    Dim Version2 As New Version("1.3.2.1")
    
    If Version1 > Version2 Then
                MessageBox.Show("Version 1 is newer")
    ElseIf Version2 > Version1 Then
                MessageBox.Show("Version 2 is newer")
    Else
                MessageBox.Show("Both versions are the same")
    End If
    Last edited by chris128; Jul 25th, 2010 at 08:51 AM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4

    Thread Starter
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Re: Comparing versions = Headache

    I told you it probably was a neat way of doing this

    Thank you both
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem
    Disclaimer: I am not a professional programmer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width