Support Forums
Compare Version Numbers - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: Compare Version Numbers (/showthread.php?tid=18503)



Compare Version Numbers - cipherwar - 05-04-2011

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


RE: Compare Version Numbers - KoBE - 05-04-2011

(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



RE: Compare Version Numbers - cipherwar - 05-04-2011

thk, i implemented now this:

versionIsActual = String.Compare(My.Application.Info.Version.ToString, actualVersion)


RE: Compare Version Numbers - Modestep - 05-10-2011

You can try:
Code:
if string1 <> string2 then
This way you will check of the 2 strings are equal or not.