Highlighted

Convert Form result to a number

Participant ,
Mar 11, 2019

Copy link to clipboard

Copied

Hello,

I need to take the value submitted in a form and add 99 to it. I first tried:

<cfset channel.type = 'Form[P#c#Channel]' + 99>

That failed since the form value is a string not a number.

Then I tried:

<cfset channel.type = LSParseNumber('Form[P#c#Channel]') + 99> and got

Form[P1Channel] must be interpretable as a valid number in the current locale.

How can I change the submitted value to a number that I can perform addition on?

Thanks!

Gary

Wait a minnit.. are you using 'channel' as a struct or array???  That might be the culprit.  It makes no sense for CF to think '5' is a scalar variable, but it could think 'channel' is a string, not a struct or array.

V/r,

^ _ ^

Views

456

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Convert Form result to a number

Participant ,
Mar 11, 2019

Copy link to clipboard

Copied

Hello,

I need to take the value submitted in a form and add 99 to it. I first tried:

<cfset channel.type = 'Form[P#c#Channel]' + 99>

That failed since the form value is a string not a number.

Then I tried:

<cfset channel.type = LSParseNumber('Form[P#c#Channel]') + 99> and got

Form[P1Channel] must be interpretable as a valid number in the current locale.

How can I change the submitted value to a number that I can perform addition on?

Thanks!

Gary

Wait a minnit.. are you using 'channel' as a struct or array???  That might be the culprit.  It makes no sense for CF to think '5' is a scalar variable, but it could think 'channel' is a string, not a struct or array.

V/r,

^ _ ^

Views

457

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 11, 2019 0
LEGEND ,
Mar 11, 2019

Copy link to clipboard

Copied

<cfset channel.type = INT(form['P#c#Channel']) + 99 />

Part of the issue is that you are placing form within the quote, which is what not to do.    Form needs to be outside the string delimiter so that CF knows you're trying to access a value in the form scope.

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
Participant ,
Mar 11, 2019

Copy link to clipboard

Copied

Thank you!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
Participant ,
Mar 11, 2019

Copy link to clipboard

Copied

I probably should have tested it first...(before marking as correct)

<cfset channel.type = INT(form['P#c#Channel']) + 99 />

That returns:

You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
LEGEND ,
Mar 11, 2019

Copy link to clipboard

Copied

Ignore my last post.  I hate the Jive platform!!!  It's not letting me delete it.  (I had to close the browser and re-logon to finally delete it.)

Try val() instead of int.  Although the scalar error message confuses me.  Are you sure that the form submits a single value?

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
Participant ,
Mar 11, 2019

Copy link to clipboard

Copied

Maybe this will help. I dumped the form values.Screen Shot 2019-03-11 at 4.58.30 PM.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
LEGEND ,
Mar 11, 2019

Copy link to clipboard

Copied

Very odd.  Try LSParseNumber, again, with the quotes in the right place.  If that doesn't work, I don't know.. I've never seen CF declare '5' as a scalar variable.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
LEGEND ,
Mar 11, 2019

Copy link to clipboard

Copied

Wait a minnit.. are you using 'channel' as a struct or array???  That might be the culprit.  It makes no sense for CF to think '5' is a scalar variable, but it could think 'channel' is a string, not a struct or array.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
Participant ,
Mar 11, 2019

Copy link to clipboard

Copied

I changed channel.type to just channel and it works.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 1
LEGEND ,
Mar 12, 2019

Copy link to clipboard

Copied

Glad to hear you got it fixed.  And thank you for marking my answer as correct.  I do appreciate it.

V/r,

^ _ ^

UPDATE:  Actually, now that I think of it, if you declare channel a struct, THEN try to save it as "channel.type", that might work.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 12, 2019 0
LEGEND ,
Mar 12, 2019

Copy link to clipboard

Copied

Try this:

<cfset channel = {} />  <!--- Implicit create --->

or

<cfset channel = StructNew() />  <!--- Expressed create --->

Then start working with your form scope.

<cfset channel.type = lsParseNumber(form['P#c#Channel']) + 99 />

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 12, 2019 0