CFLib.org – Common Function Library Project

Logic2bit(exp)

Last updated June 26, 2002

author

Joseph Flanigan

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Use this function where logic constants like TRUE and FALSE cannot be used. A non-bit value -1 is used when valid expression is not a logic value.

Return Values:
Returns a Boolean.

Example:

<CFOUTPUT>
Logic2bit(TRUE): #Logic2bit(TRUE)#<BR>
Logic2bit("No"): #Logic2bit("No")#<BR>
Logic2bit("fred"): #Logic2bit("fred")#<BR>
Logic2bit(NOT TRUE): #Logic2bit(NOT TRUE)#<BR>
Logic2bit(0): #Logic2bit(0)#<BR>
Logic2bit(50 NEQ 50): #Logic2bit(50 NEQ 50)#
</CFOUTPUT>

Parameters:

Name Description Required
exp Expresison to evaluate Yes

Full UDF Source:

/**
 * Converts logic bit constants (TRUE, &quot;Yes&quot;, 1,FALSE,&quot;No&quot;,0) or logical expressions to bit values (1,0).  A non-boolean value returns a -1 value.
 * 
 * @param exp      Expresison to evaluate (Required)
 * @return Returns a Boolean. 
 * @author Joseph Flanigan (joseph@switch-box.org) 
 * @version 1, June 26, 2002 
 */
function Logic2bit(exp){
 if (IsBoolean(exp)){
  if (exp) return 1;
  if (NOT (exp)) return 0;
}
else return(-1);
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson