Support Forums

Full Version: Compare Version Numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hallo,
I try to compare the version of my program with the version-number given by a PHP Serverapplication, both are Strings like x.y.z.a

But comparison with "<" does not work.

My code is like this:
Code:
Public Function versionCheck(ByVal sURL As String) As String
        Dim tmp As String = ""
        ' Prüft, ob die angegebene URL erreichbar ist
        Try
            Dim uri As New Uri(sURL)
            If (uri.Scheme = uri.UriSchemeHttp) Then
                Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
                request.Method = WebRequestMethods.Http.Get
                Dim response As HttpWebResponse = request.GetResponse()
                Dim reader As New StreamReader(response.GetResponseStream())
                tmp = reader.ReadToEnd()
                response.Close()
            End If
            Return tmp

        Catch ex As Exception
            log("myApp, version Check", ex.Message)
            ' URL not reached
            Return ex.Message
        End Try
    End Function

and this:

Code:
Dim infoString As String
        Dim actualVersion As String
        Try
            If (MC.a2UseLocalhost = True) Then
                actualVersion = MC.versionCheck("http://localhost/test-version.php")
            Else
                actualVersion = MC.versionCheck("http://ww.mytestserver.com/test-version.php")
            End If

            infoString = "Your Version: " & My.Application.Info.Version.ToString & vbCrLf & "Actual Version: " & actualVersion
            ' following does not work
            If (My.Application.Info.Version.ToString < actualVersion) Then
            infoString &= "Update needed!" & vbCrLf
            Else
            infoString &= "Programversion OK!" & vbCrLf
            End If
            MessageBox.Show(infoString)
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message)
        End Try


Seems as if the comparison of "1.0.0.0" and "1.0.0.1" with character "<" does not work.

Any idea what's going wrong here??Unsure
(05-04-2011, 03:45 AM)cipherwar Wrote: [ -> ]Seems as if the comparison of "1.0.0.0" and "1.0.0.1" with character "<" does not work.

Any idea what's going wrong here??Unsure

Are you just trying to see if the strings are equal? This should work for you.

Code:
.
        If string1 = string2 Then
            'same version
        Else
            'different versions
        End If
thk, i implemented now this:

versionIsActual = String.Compare(My.Application.Info.Version.ToString, actualVersion)
You can try:
Code:
if string1 <> string2 then
This way you will check of the 2 strings are equal or not.