;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       Bool() 
;; 
;;ACTION         return True if Flag is "non-zero", "T", "Y", or "ON" 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.1  - 2014/03/14 
;; 
;;HISTORY        1.0  - 2007/05/17 
;;               1.1  - 2014/03/14 - Preserve state of @ERROR for use with embedded calls. 
;;                                   ($Bv = Bool(ReadProfileString(...)) will return the 
;;                                   error from the ReadProfileString() call. 
;; 
;;SYNTAX         Bool(flag [,other_true] [,default]) 
;; 
;;PARAMETERS     Flag    - REQUIRED, a text string - can be null 
;; 
;;               Extra   - OPTIONAL, a string of other "true" matches, comma-delimited. 
;;                         "En*" will match the leftmost 2 chars 
;; 
;;               Default - OPTIONAL, a default value to use if Flag is null 
;; 
;;REMARKS        Returns TRUE if any of the following condidions are met: 
;;			First char of flag is "Y"  (yes) 
;;			First char of flag is "T"  (true) 
;;			First char of flag is a non-zero digit 
;;			Flag text is "ON" 
;;			Flag text matches optional Extra value 
;; 
;;RETURNS        1 if the flag evaluates to a "true" boolean, 0 otherwise 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    WXP-Win8, W2K-W2K12r2 
;; 
;;EXAMPLES       If Bool(ReadProfileString('config.ini', 'sect', 'setting') 
;;                 'Setting is on!' ? 
;;               EndIf 
;; 
;;               ; In this configuration, the default is T, and the config.ini value is 
;;               ; used to turn it off. If the setting in the ini file is not defined,  
;;               ; the default value is used. 
;;               $Default = 'T' 
;;               If Bool(ReadProfileString('config.ini', 'sect2', 'setting'), '', $Default) 
;;                 'Setting is on!' ? 
;;               EndIf 
;  
Function Bool($_Flag, OPTIONAL $_Extra, OPTIONAL $_Default)
 
 
  Dim $_aXV, $_XV			; array of text match values and enumerator 
  Dim $_bT, $_bF			; Boolean True & False values 
  Dim $_Err				; incoming Error state 
 
  $_bT = Not 0				; TRUE value 
  $_bF = Not $_bT			; FALSE value 
 
  ; Handle embedded ReadLine errors passed to this wrapper func 
  $_Err = @ERROR
 
  ; set default value if defined and test value (Flag) is not defined 
  If $_Flag = '' And $_Default <> ''
    $_Flag = $_Default
  EndIf  
 
  $_Flag = UCase($_Flag)		; force uppercase chars 
 
  $Bool = $_bF				; default to FALSE 
 
  If $_Extra
    $_Extra = 'ON,TRUE,T,YES,Y,' + $_Extra
  Else
    $_Extra = 'ON,TRUE,T,YES,Y'		; default test values 
  EndIf
 
  ; Handle the numeric test 
  If Val($_Flag) <> 0			; flag is non-zero 
    $Bool = $_bT
  EndIf
 
 
  ; process string comparisons 
  If Not $Bool
    $_aXV = Split($_Extra, ',')		; get array of string match values 
    For Each $_XV in $_aXV		; then compare each one 
      If InStr($_XV, '*')		; is it a substring compare? 
        If UCase(Left($_XV, InStr($_XV, '*') - 1)) = Left($_Flag, InStr($_XV, '*') - 1)
          $Bool = $_bT
        EndIf
      Else				; or a direct compare 
        If UCase($_XV) = $_Flag
          $Bool = $_bT
        EndIf
      EndIf
    Next
  EndIf
 
  Exit $_Err				; Return error state when called 
 
EndFunction