[thelist] CFTRY/CFCATCH

.jeff jeff at members.evolt.org
Tue Mar 26 12:29:01 CST 2002


connie (?),

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Starkey Connie - cstark
>
> In the following code, I want to look at the volume
> discount percent and amount fields and if they are
> blank, to default them to 0's. I was considering using
> CFTRY/CFCATCH.  Can someone tell me if there is a
> better solution?
>
> <cfloop index="x" from="1" to="#length#">
> 	<cfset ItemCodes = ListGetAt(#qBillingView.ItemCodes#,x)>
> 	<cfset ItemPrices = ListgetAt(#qBillingView.ItemPrices#,x)>
> 	<cfset Percent = ListgetAt(#qBillingView.volumediscountpercent#,x)>
> 	<cfset Amount = ListgetAt(#qBillingView.volumediscountamount#,x)>
> 	<cfset ItemCodeDescription = ListgetAt(#qBillingView.ItemCodeDescription#,x)>
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

cftry/cfcatch is intended for catching and managing execution errors, database errors, etc.  it's probably overkill for what you're trying to do.  it seems that you want to just enforce values to numeric.  that's as simple as using the Val() function.

<cfset amount = Val(ListGetAt(qbBillingView.volumndiscountamount, x))>

however, i'm not totally clear on what you want to do in the code above so i'll also  respond to things i see that could use improvement.

if you're referring to variables inside of coldfusion functions, you don't need to wrap the variables in hashes.  see my line of sample code above.  notice though that i've left "length" wrapped in hashes.  that's be cause the "to" attribute is expecting a string/number value.  rather than hardcode that value you're using a variable that holds that value.  so, in this case you need the hashes.

a really good article about this issue can be found on doug nottage's site.  if you've never heard of him, let's just say he's behind autobytel.com, one of the first uber-auto sites on the net.

http://doug.nottage.com/cf/index.cfm?id=37

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list