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);
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson