Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cannot convert the value "lower" to a boolean

Participant ,
Jun 23, 2008 Jun 23, 2008
I am trying to work out why this example gives me an error, it is meant to demonstrate the ability to return a data type other than a Boolean from a UDF but doesn´t seem to work. Why is that? I'm using cfmx7 which shouldn´t matter as udfs are cf5+ Thanks for any replies
TOPICS
Getting started
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 23, 2008 Jun 23, 2008
Hydrowizard wrote:
> Thanks for the reply Phil, sorry I forgot to put that the error message is
> "cannot convert the value "lower" to a boolean". The return false part came in
> the code- I got rid of it now, I did think that it was always necessary though
> thanks for pointing that out.
>

Have your resolved your error?

If not, or for others it is in your first if clause:
<cfif not isUpperOrLowerCase("a")>

You are not comparing the function to anything so CF is trying to
convert the re...
Translate
Mentor ,
Jun 23, 2008 Jun 23, 2008
Why do you have a return false following your if .. return "upper" .. else .. return "lower"? And, you might want to post the particular error that you are getting in the future.

Phil
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 23, 2008 Jun 23, 2008
Thanks for the reply Phil, sorry I forgot to put that the error message is "cannot convert the value "lower" to a boolean" in the message body! The return false part came in the code direct from the tutorial I got rid of it now- so does anyone know why this error happens?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008
Hydrowizard wrote:
> Thanks for the reply Phil, sorry I forgot to put that the error message is
> "cannot convert the value "lower" to a boolean". The return false part came in
> the code- I got rid of it now, I did think that it was always necessary though
> thanks for pointing that out.
>

Have your resolved your error?

If not, or for others it is in your first if clause:
<cfif not isUpperOrLowerCase("a")>

You are not comparing the function to anything so CF is trying to
convert the returned value 'lower' in this case to either true or false,
i.e. a boolean value, and failing. So it is telling you that it can not
convert 'lower' into a boolean value.

Now this would give it no problem.

<cfif not isUpperOrLowerCase("a") EQ 'lower'>

But then I am not sure what that is really testing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 23, 2008 Jun 23, 2008
Thanks Ian yes it is complicated! I don't see what the "a" string actually does in the cfifs it doesn't seem to be checking anything. I have attached the part of the tutorial that explains what he is on about. Thanks for sorting it out, interesting to hear what you think about it:
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008
Hydrowizard wrote:
>
> That will do for those functions. Now, let's build a function to decide if it
> is upper or lower case, and alert us to that. We'll return the value "upper",
> "lower", or "false" depending on the character passed.
>
> <cfscript>
> function isUpperOrLowerCase(character) {
> if (Asc(character) gte 65 and Asc(character) lte 90)
> return "upper";
> else if (Asc(character) gte 97 and Asc(character) lte 122)
> return "lower";
> return false;
> }
> </cfscript>
>
> We can use the function in this way:
>
> <cfif not isUpperOrLowerCase("a")>
> This is not a character.
> <cfelseif isUpperOrLowerCase("a") eq "upper">
> This is an uppercase character.
> <cfelse>
> This is a lowercase character.
> </cfif>
>

Where is this from? It is either a bad and|or an outdated example!

The function can either return the strings 'upper' or 'lower' or boolean
false. The strings can not or should not be converted to boolean so how
are they to pass the first if statement. Does anybody know if this
previously worked in CF?

I would write that something like this:
<cfscript>
function isUpperOrLowerCase(character) {
if (Asc(character) gte 65 and Asc(character) lte 90)
return "upper";
else if (Asc(character) gte 97 and Asc(character) lte 122)
return "lower";
return "unknown";
}
</cfscript>

...

<cfif isUpperOrLowerCase("a") eq "unknown">
This is not a character.
<cfelseif isUpperOrLowerCase("a") eq "upper">
This is an uppercase character.
<cfelse>
This is a lowercase character.
</cfif>

But then I would immediately ask a resource such as this or House Of
Fusion if there is a better way to re-factor this clunky code.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008
> I have attached the part
> of the tutorial that explains what he is on about.

Where'd this tutorial come from? Just so I know to avoid the resource in
future, I mean.

For the purposes what what you're doing - "[how] to return a data type
other than a Boolean from a UDF" - I think the online docs pretty much
cover everything you need to know. Plus the code actually works (usually).

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008
your function isUperOrLowerCase() is fine, leave that return false in there:

function isUpperOrLowerCase(character) {
if (Asc(character) gte 65 and Asc(character) lte 90)
return "upper";
else if (Asc(character) gte 97 and Asc(character) lte 122)
return "lower";
return false;
}

your cfif block should be re-organized, though, to work properly:

<cfif isUpperOrLowerCase("a") eq "upper">
This is an uppercase character.
<cfelseif isUpperOrLowerCase("a") eq "lower">
This is a lowercase character.
<cfelse>
This is not a character.
</cfif>

hth


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 24, 2008 Jun 24, 2008
LATEST
it is a sitepoint tutorial thanks for all the help
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources