MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Browse Dialog - Changing Directory[Next]: Files In Use - ADD
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->File and Directory->File Version Compare Code

File Version Compare Code

The following code demonstrates a VBSCRIPT function which will compare file version numbers such as ("5.60.1234.0001" and "5.60"). It is in the form of a macro so that you could define it in your common header file and refer to the macro in any "VbsCa" code that needed it.

The macro is demonstrated/used in the "MDAC not too old?" launch condition section.

;--- Define Return codes ----------------------------------------------------
#define FILEVER_RC_F1_EQUAL_F2          0
#define FILEVER_RC_F1_LESS_THAN_F2     -1
#define FILEVER_RC_F1_GREATER_THAN_F2   1

;--- Define the macro -------------------------------------------------------
#(  '<?NewLine>'
    ;--- Define macro used to include this code -----------------------------
    #define INCLUDE_VBSCRIPT_FUNCTION-CompareFileVersions   ;;Version 08.194

    '========================================================================
    function CompareFileVersions(VerF1, VerF2)
    '========================================================================
        '-------- Init ------------------------------------------------------
        on error resume next
        CompareFileVersions = <$FILEVER_RC_F1_EQUAL_F2>

        '-------- Split up the version numbers ------------------------------
        dim VerBitsF1 : VerBitsF1 = split(VerF1, ".")
        dim VerBitsF2 : VerBitsF2 = split(VerF2, ".")

        '-------- How many "bits" are there (use largest of the two) --------
        dim LastIndex : LastIndex = ubound(VerBitsF1)
        if  ubound(VerBitsF2) > LastIndex then
            LastIndex = ubound(VerBitsF2)
        end if

        '-------- Work through each of the bits (probably 4) ----------------
        dim i
        for i = 0 to LastIndex
            '--- Work out the 2 "bits" to compare (use "0" on shorter versions) ---
            dim BitF1, BitF2
            if  i <= ubound(VerBitsF1) then BitF1 = VerBitsF1(i) else BitF1 = ""
            if  i <= ubound(VerBitsF2) then BitF2 = VerBitsF2(i) else BitF2 = ""
            if  BitF1 = "" then  BitF1 = "0"        ;;May as well be paranoid...
            if  BitF2 = "" then  BitF2 = "0"

            '-------- Compare the values (exit when mismatch found) ---------
            if  cint(BitF1) > cint(BitF2) then
                CompareFileVersions = <$FILEVER_RC_F1_GREATER_THAN_F2>
            else
                if  cint(BitF1) < cint(BitF2) then
                    CompareFileVersions = <$FILEVER_RC_F1_LESS_THAN_F2>
                end if
            end if
            if CompareFileVersions <> <$FILEVER_RC_F1_EQUAL_F2> then exit for
        next
    end function
#)


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006 & 2007 for the Windows SDK (Windows Installer) area.This external link was OK when tested at 27 Dec 2008Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Browse Dialog - Changing Directory[Next]: Files In Use - ADD


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday December 27 2008 at 3:15pm
Visit MAKEMSI's Home PageThis external link was OK when tested at 7 Dec 2008

HTML page dated Mon, 29 Jan 2007 00:11:11 GMT
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006 & 2007 for the Windows SDK (Windows Installer) area.This external link was OK when tested at 27 Dec 2008