• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 71
  • Last Modified:

Adding two numbes together

Hi,


I am trying to add my numbers together but nothing is working my logic as always is off.  

specially around the holidays.  

So, I need your help please!!!


<cfoutput query="FiveYearPlan"> 
            <cfset CostPlan = #replace(FiveYearPlan.MajorUpgradeCost,"<","&lt;")#>
            <cfset variables.CostPlanFrom = 0>
			
	<cfif #CostPlan# neq ''>
				<cfswitch expression="#CostPlan#">
 				<cfcase value="&lt;$100K">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 0>
                    0
 				</cfcase>
 				<cfcase value="$100K to $500K">
                	<cfset variables.CostPlanFrom = variables.CostPlanFrom + 100>
                    100
 				</cfcase>
 				<cfcase value="$500K to $1M">
                	<cfset variables.CostPlanFrom = variables.CostPlanFrom + 500>
 					500
 				</cfcase>
 				<cfcase value="$1M to $5M">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 1000000>
 					1000000
 				</cfcase> 
                <cfcase value=">$5M">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 5000000>
 					5000000
 				</cfcase>
                </cfswitch> 
           <cfelse>
           &nbsp;
           </cfif>
</cfoutput>		


<!--- variables.CostPlanFrom is not adding up ---> 
<!--- What am I doing wrong? ---> 

<cfoutput>#variables.CostPlanFrom#</cfoutput>  

Open in new window

0
lulu50
Asked:
lulu50
  • 2
  • 2
1 Solution
 
gdemariaCommented:
lol,  especially around the holidays!

I'm thinking that some of your switch cases are not matching.
Let's find out which ones by using the defaultcase...

<cfoutput query="FiveYearPlan"> 
            <cfset CostPlan = replace(FiveYearPlan.MajorUpgradeCost,"<","&lt;")>
            <cfset variables.CostPlanFrom = 0>
			
          	<cfif #CostPlan# neq ''>
				<cfswitch expression="#CostPlan#">
 				<cfcase value="&lt;$100K">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 0>
                    0
 				</cfcase>
 				<cfcase value="$100K to $500K">
                	<cfset variables.CostPlanFrom = variables.CostPlanFrom + 100>
                    100
 				</cfcase>
 				<cfcase value="$500K to $1M">
                	<cfset variables.CostPlanFrom = variables.CostPlanFrom + 500>
 					500
 				</cfcase>
 				<cfcase value="$1M to $5M">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 1000000>
 					1000000
 				</cfcase> 
                <cfcase value=">$5M">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 5000000>
 					5000000
 				</cfcase>
				<cfdefaultcase>
				   Could not match [#costPlan#]
				</cfdefaultcase>
                </cfswitch> 
           <cfelse>
              Empty CostPlan
           </cfif>
		   <br>
</cfoutput>		

Open in new window


If your query FiveYearPlan has an ID for each of the values, it might be better to use the ID in the cfswitch for an easier match.
0
 
lulu50Author Commented:
gdemaria I agree!!!!

having this defaultcase thing helps a lot specially around the holidays.  

I found the issue and fixed it thank you again.
0
 
lulu50Author Commented:
Thank you
0
 
gdemariaCommented:
ha, yes, I always like using defaultcase around the holidays to help spot little problems, like who did I forget to buy a present for! :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now