Solved

Adding two numbes together

Posted on 2014-12-19
4
64 Views
Last Modified: 2014-12-19
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
Comment
Question by:lulu50
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 40509529
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
 

Author Comment

by:lulu50
ID: 40509631
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
 

Author Closing Comment

by:lulu50
ID: 40509632
Thank you
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 40509665
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now