I should probably keep my nose out of this one. :)

> Ah... this is why competition is good.

> I don't have a new feature, per se, but I do have a pet
> peeve that came about from porting an app written in
> another language to an online CF version.

> The CFCASE portion of CFSWITCH is sorely limited in its
> ability to handle parameters.  It can't do ranges, and if
> it could it can't mix multiple parameters on the same
> line.  Look at the following case argument written in
> another language:

> SELECT CASE carval%
>    CASE 1 TO 50000:H6.VL = "500":H7.VL = "500"
>    CASE 50001 TO 100000:H6.VL = "1,000":H7.VL = "1,000"
>    CASE IS > 100000:H6.VL = "2,500":H7.VL = "2,500"
> END SELECT

What's that VB? VB's the only language I'm familiar with that uses
select-case rather than switch-case ... and I've never seen ranges used in a
case statement, although I have occasionally wished that there were a method
for it... There are of course, other ways to accomplish this:

<cfset myarray = arraynew(1)>
<cfset myarray[1] = 100001>
<cfset myarray[2] = 50001>
<cfset myarray[3] = 1>
<cfloop index="x" from="1" to="#arraylen(myarray)#">
        <cfset mylocalvariable = min(mylocalvariable,myarray[x])>
</cfloop>
<cfswith expression="#mylocalvariable#">
        <cfcase value="1"></cfcase>
        <cfcase value="50001"></cfcase>
        <cfcase value="100001"></cfcase>
</cfswitch>

This is even assuming that there isn't a faster / easier way to do this in a
formulaic manner, i.e.

<cfset mylocalvariable = ceiling(myquery.mycolumn / 50000)>
<cfswitch expression="#mylocalvariable#">
        <cfcase value="1"></cfcase>
        <cfcase value="2"></cfcase>
        <cfdefaultcase></cfdefaultcase>
</cfswitch>

> 5 lines of code, total.  While you could do this without
> *too* much more CF code, this is a very simple example.
> Doing U.S. ZIP code ranges, where you are selecting
> combinations of individual ZIPs and ranges - can be coded
> in a LOT fewer lines if you allow something like the
> following:

> <CFSWITCH EXPRESSION="#variables.ZIPCode#>
>    <CFCASE VALUE="LT 93711">
>       ...blahblahblah...
>    </CFCASE>
>    <CFCASE VALUE="93712, 93713 TO 93940, 93950, 94086 TO
>    95050">
>       ...blahblahblah...
>    </CFCASE>
>    <CFCASE VALUE="GT 93940">
>       ...blahblahblah...
>    </CFCASE>
> </CFSWITCH>

I dunno if I'd use zip-codes as an example of common usage ... GIS is a
pretty hefty subject in and of itself.

I suspect if I wanted to do something like this in CF I would probably wind
up using the database, structures or a 5-dimensional array ( one dimension
for each digit in the zip code ) ... most likely database ... I could write
a case statement in sql server with ranges, though that has a lot to do with
the cases in sql server ( not sure about other db servers ) being scalar
expressions (?) is that the right term?... In any event, any one of the
three solutions is liable to be more efficient than a horde of <cfif>
statements as I think many of us may be apt to launch into, just because the
the structure and array solutions may not be very intuitive and the db
solution requires sql knowledge that many of us haven't mastered.


Isaac
Certified Advanced ColdFusion 5 Developer

www.turnkey.to
954-776-0046

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.

Reply via email to