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

Help with multiple variable

New Here ,
Dec 28, 2007 Dec 28, 2007

Copy link to clipboard

Copied

I'm trying to write a query which pulls shipment information from an access database. Then it grabs the weight of each shipments and multiplies it by the corresponding rate depending on its weight class.

I'm using the CFIF, CFELSEIF and CFSET tags to try to accopmlisht this, making it look something like this

<CFIF "Shipments.weight" LT 500 >
<cfset Shipments.rate = 7.5 >
<CFELSEIF "Shipments.weight" GT 499 LT 1000 >
<cfset Shipments.rate = 7 >
<CFELSEIF "Shipments.weight" GT 999 LT 2000 >
<cfset Shipments.rate = 6.5 >
<CFELSEIF "Shipments.weight" GT 1999 LT 5000 >
<cfset Shipments.rate = 5 >
<CFELSEIF "Shipments.weight" GT 4999 >
<cfset Shipments.rate = 3.65 >
</CFIF>

then in the Output tag I use this CFSCRIPT

<cfscript>
WriteOutput(#ACC_Report.weight#/100*#Shipments.rate#);
</cfscript>

It runs fine but it only seems to grab either the first or the second set rate variables and multiplies all the weights in the output query by it, inetead of logically choosing its weight class.

Any help, perhaps I'm using the wrong logic.

Thanks in advance
TOPICS
Advanced techniques

Views

425

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
community guidelines
LEGEND ,
Dec 28, 2007 Dec 28, 2007

Copy link to clipboard

Copied

First, take the quotes out of the cfif and cfelseif tags.

Next, are you looping through your query results at all to determine the shipments.rate?

Next, if shipments.rate is part of your query, use QuerySetCell to change the value, not cfset.

Finally, this would be a lot easier if you stored the rate in your db.

Votes

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
community guidelines
New Here ,
Dec 28, 2007 Dec 28, 2007

Copy link to clipboard

Copied

Thanks,

I do have a table set up for just the rates but haven't used it since I wanted to make sure which language logic and tags I needed to use.

I will try QuerySetCell to change the value.

Votes

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
community guidelines
New Here ,
Dec 28, 2007 Dec 28, 2007

Copy link to clipboard

Copied

I'm not using the loop function if it helps to know. I'm just recalling the weight values from each shipment's respective cell using their delivery date criteria. This is all information manually added by data entry personel anyway so I have to do is make the site do the math for the rate charge. There are 7 different rates depending on how much each shipment weights, just need to logically write the correct phrase so each weight value is multiply by the rate bracket they belong to.

Votes

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
community guidelines
LEGEND ,
Dec 28, 2007 Dec 28, 2007

Copy link to clipboard

Copied

> <CFELSEIF "Shipments.weight" GT 499 LT 1000 >

This syntax is wrong.

What you are saying here is this:

("Shipments.weight" GT 499) LT 1000

The bit in the parentheses is nonsense, really, as you're comparing a
string to a number for "greater-than-ness". CF will cast both to a string,
and then try to work out "greater-than-ness" on the two strings. There's
no such thing as "greater-than-ness" on string data, but CF won't error
(which sensibly it should), it will do some
ascii-character-translation-mumbo-jumbo, and come up with the fact that
"Shipments.weight" (not your variable called that, mind, but that *exact*
string) is "greater than" "499", because "S" has a higher ASCII code than
"4" (or because "Shipments.weight" is longer than "499" or something
equally pointless).

But whichever way one spins it: the answer to the first bit is TRUE.

So now you have this:

TRUE LT 1000.

Same problem: CF can't do that, so it converts TRUE into number this time.

1 LT 1000.

Sure is.

But that's not really what you meant to ask.

What you meant to ask is whether Shipments.weight (the variable, not a
string of those letters) is between 499 and 1000. Or put differently,
whether Shipments.weight is greater than 499, but Shipments.weight is also
less than 1000.

<cfelseif (Shipments.weight GT 499) and (Shipments.weight LT 1000)>

etc

--
Adam

Votes

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
community guidelines
LEGEND ,
Dec 28, 2007 Dec 28, 2007

Copy link to clipboard

Copied

"There's no such thing as "greater-than-ness" on string data"

Adam, everything you said is basically true and relevant to the original
poster's issue. But this line is wrong is it not? Isn't comparing one
string to another and determining which is greater or lesser the essence
of sorting a set of strings into an alphabetical order?

Now, I am not sure I can remember the last time I had to write my own
sort routine. But I am pretty sure when I did for sorting string data,
I communally compared one to another to see which was greater and|or
lesser then the other.

To reiterate in the original post, the person is comparing the string
constants "Shipments.weight" to the numbers do to the improper quotes,
not the value in the Shipments.weight variable.

Also, if one cares, the logic could be greatly simplified with some
basic boolean logic. The lower range comparisons are unnecessary.

<CFIF Shipments.weight LT 500 >
<!--- weight is less then 500 --->
<cfset Shipments.rate = 7.5 >

<CFELSEIF Shipments.weight LT 1000 >
<!--- weight is greater then equal to 500 it was not caught in first
branch, but it is also less then 1000 --->
<cfset Shipments.rate = 7 >

<CFELSEIF Shipments.weight LT 2000 >
<!--- weight is greater then equal to 1000 it was not caught in any
previous branch, but it is also less then 2000--->
<cfset Shipments.rate = 6.5 >

<CFELSEIF Shipments.weight LT 5000 >
<!--- weight is greater then equal to 2000 it was not caught in any
previous branch, but it is also less then 5000--->
<cfset Shipments.rate = 5 >

<CFELSE>
<!--- weight is greater then equal to 5000 it was not caught in any
previous branch--->
<cfset Shipments.rate = 3.65 >
</CFIF>

Votes

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
community guidelines
LEGEND ,
Dec 28, 2007 Dec 28, 2007

Copy link to clipboard

Copied

> "There's no such thing as "greater-than-ness" on string data"
>
> Adam, everything you said is basically true and relevant to the original
> poster's issue. But this line is wrong is it not? Isn't comparing one
> string to another and determining which is greater or lesser the essence
> of sorting a set of strings into an alphabetical order?

You're absolutely right. I didn't think of that (which makes me feel
daft!)

Good work ;-)

--
Adam

Votes

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
community guidelines
Community Expert ,
Dec 29, 2007 Dec 29, 2007

Copy link to clipboard

Copied

LATEST
Hi Drakken98,

I understand you wished to say something like

<CFIF Shipments.weight LT 500 >
<cfset Shipments.rate = 7.5 >
<CFELSEIF Shipments.weight GTE 500 AND Shipments.weight LT 1000 >
<cfset Shipments.rate = 7 >
<CFELSEIF Shipments.weight GTE 1000 AND Shipments.weight LT 2000 >
<cfset Shipments.rate = 6.5 >
<CFELSEIF Shipments.weight GTE 2000 AND Shipments.weight LT 5000 >
<cfset Shipments.rate = 5 >
<CFELSEIF Shipments.weight GTE 5000 >
<cfset Shipments.rate = 3.65 >
</CFIF>

Votes

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
community guidelines
Resources
Documentation