Copy link to clipboard
Copied
Hi. I just have a simple number range and I want to output the results. What I have outputs the results, but for some reason, it only displays the first result. Why does it not display the correct result? Here's what I have:
<cfset X = 27>
<cfset Y = 37>
<cfif (#X# GT 35 LT 51 And #Y# GT 1 LT 35)>
<cfset Result = 200>
<cfelseif (#X# GT 1 LT 35 And #Y# GT 35 LT 51)>
<cfset Result = 300>
<cfelseif (#X# GT 35 LT 51 And #Y# GT 35 LT 51)>
<cfset Result = 100>
</cfif>
<cfoutput>
#Result#
</cfoutput>
Since X is 27 and Y is 37 it should output 300 as the result, but it outputs 200. Why is this? What do I do to fix this? Thanks.
Andy
Basically you are trying to use the logic X>35<51 and I don't think CF supports this form of "between" logic and I have no clue as to what logic CF is actually performing. I'm surprised it is not puking out an error message. Instead try:
<cfif X GT 35 and X LT 51 and Y GT 1 and Y LT 35>
<cfset Result = 200>
<cfelseif X GT 1 and X LT 35 and Y GT 35 and Y LT 51>
<cfset Result = 300>
<cfelseif (X GT 35 and X LT 51 and Y GT 35 and Y LT 51>
<cfset Result = 100>
</cfif>
Also Result is undefined if all those c
...Copy link to clipboard
Copied
Basically you are trying to use the logic X>35<51 and I don't think CF supports this form of "between" logic and I have no clue as to what logic CF is actually performing. I'm surprised it is not puking out an error message. Instead try:
<cfif X GT 35 and X LT 51 and Y GT 1 and Y LT 35>
<cfset Result = 200>
<cfelseif X GT 1 and X LT 35 and Y GT 35 and Y LT 51>
<cfset Result = 300>
<cfelseif (X GT 35 and X LT 51 and Y GT 35 and Y LT 51>
<cfset Result = 100>
</cfif>
Also Result is undefined if all those conditions fail so it would be wise to include a final <cfelse> block.
Copy link to clipboard
Copied
Thank you Steve. This works! I have a few more ranges to add to this and I have input boxes to type in numbers. Each input box can only have a certain range of numbers be entered into each one. If a larger number is entered, a message will pop up saying that they need to enter between this number and this number. I was just taking the code I had and trying to simplify it so I could get this to work. I did not think of trying it the way you did.