;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       kfVer() 
;; 
;;ACTION         Exits if not running minimum KixForms version 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        2.0 - 2009/03/01 
;; 
;;HISTORY	 1.0 - 2007/10/25 - Initial Release 
;;               2.0 - 2009/03/01 - rewrite with better weighting system 
;; 
;;SYNTAX         kfVer([Version]) 
;; 
;;PARAMETERS     Version - OPTIONAL - String 
;;               - Minimum allowed KF version 
;; 
;;REMARKS        Checks the KF version, returns error if not available or below minimum 
;; 
;;RETURNS        String holding Version, Bool - True if version is at/above defined ver. 
;;		 String - Current KF version if arg is empty,  
;;		 Bool	- True/False if version is below that defined by the argument 
;; 
;;DEPENDENCIES   KixForms.DLL (classic) 
;; 
;;TESTED WITH    W2K, WXP, W2K3, Vista, X64 
;; 
;;EXAMPLES       If kfVer('2.46.55.0') 
;;		   'Kixforms is installed and current!' ? 
;;		   'Kixforms version ' kfVer() ' is installed.' 
;;		 EndIf 
;; 
; 
Function kfVer(OPTIONAL $_Version)
 
  Dim $_oSys					; System KixForms object 
  Dim $_aVer					; Array of version fields 
  Dim $_X, $_Max, $_Val, $_Wt			; Index, Max, Value & Weight vars 
  Dim $_Err					; error code 
  Dim $_IVf, $_DVf				; installed and desired version field counts 
 
  $kfVer = 0
 
  $_oSys = CreateObject('Kixtart.System')	; instantiate KF object 
  $_Err = @ERROR
  $_aVer = Split($_oSys.Version, '.')		; get version as array of elements 
  $_oSys = 0					; close KF pointer 
 
  If $_Err					; could not instantiate KF 
    Exit $_Err					; so return the error 
  EndIf
 
  If $_Version					; was arg specified, then do compare 
    $_Version = Split($_Version, '.')
    $_IVf = UBound($_aVer)			; elements in installed version array 
    $_DVf = UBound($_Version)			; elements in desired version array 
 
    ; insure that the installed and desired version strings have the same number 
    ; of fields - missing fields are set to 0. 
    Select					; find highest value 
     Case $_IVf = $_DVf
      $_Max = $_IVf
     Case $_IVf < $_DVf
      $_Max = $_DVf
      ReDim Preserve $_aVer[$_Max]		; adjust array and init new values 
      For $_X = ($_IVf + 1) to $_Max $_aVer[$_X] = 0 Next
     Case $_IVf > $_DVf
      $_Max = $_IVf
      ReDim Preserve $_Version[$_Max]		; adjust array and init new values 
      For $_X = ($_DVf + 1) to $_Max $_Version[$_X] = 0 Next
    EndSelect
 
 
    ; Compare each element pair in the version strings, starting with the least-significant 
    ; If the element values are equal, they are effictively ignored. If the desired value 
    ; is greater than the installed value, the current Match Value is added to the weight, but 
    ; if the desired value is less than the installed value, the current Match Value is  
    ; subtracted from the weight. The Match Value is increased in binary form as the  
    ; significance of the version values increases. This allows mis-matched string comparisons, 
    ; such as "3.0" and "2.46.24.5", to be processed correctly. 
    $_Val = 1					; current match value 
    $_Wt = 0					; match weight 
    For $_X = $_Max to 0 Step -1
      Select
       Case $_aVer[$_X] < $_Version[$_X]
        $_Wt = $_Wt + ($_Val * -1)
       Case $_aVer[$_X] > $_Version[$_X]
        $_Wt = $_Wt + $_Val
      EndSelect
      $_Val = $_Val * 2
    Next
 
    If $_Wt >= 0
      $kfVer = 1				; equal or greater ver installed - return True 
    Else
      $kfVer = 0				; older version installed - return false 
    EndIf
  Else
    $kfVer = Join($_aVer, '.')			; no argument, just return version string 
  EndIf
 
  Exit 0
 
EndFunction