\
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
#)