Thursday, April 27, 2006

Dealing with non-standard boolean values

I am have worked with how Access and other sources deliver non-standard variances of boolean variables.

After all when you update/insert to the database, all you want is a 1 or 0.

So I created this udf to help speed that process up.

<cfset one = "false">
<cfset two = "0">
<cfset new_one = 0>
<cfset new_two = 0>

<b>default values:</b><br>
<cfoutput>
one = #one#<br>
two = #two#<br>
</cfoutput>

<cfscript>
function booleanize(value) {
if (not isboolean(value)) {
value = replacenocase(value,'on',1);
value = replacenocase(value,'off',0);
}
if (yesnoformat(value) eq 'Yes') {
value = 1;
}
if (yesnoformat(value) eq 'No') {
value = 0;
}
return value;
}
</cfscript>


<cfoutput>
<b>New Values:</b><br>
one = #booleanize(one)#<br>
two = #booleanize(two)#<br>
</cfoutput>

This includes the udf as well as the test example.

I know it sounds simple, but this is easier than having to adjust your code logic for every checkbox, access on/off or true/false value.

Think about it.

FEMA needs to be scrapped, senators say

Instead of fixing the problem, they want create a new organization in the same image. Ah but here is the punchline, they want to do this, 5 weeks before the Hurrican Season.

Amazing stupidity...

read more | digg story