>> GreenByte.info By Nick Tong (quiksilv) | Supported by: TalkWebSolutions.co.uk

Fusebox 101: Using switch and case verbs

As part of my fusebox 101 updates I've decided to show how to use the switch and case verb in fusebox.

Fusebox 101

Here is the code you will need (you can easily spot the similarities):

<cf:switch expression="#attributes.licenceType#">
   <cf:case value="1">
      <set name="attributes.processDate"   value="#dateFormat(dateAdd('m',12,now()),'dd/mm/yyyy')#"    overwrite="true" />
   </cf:case>
   <cf:case value="2">
      <set name="attributes.processDate"   value="#dateFormat(dateAdd('m',24,now()),'dd/mm/yyyy')#"    overwrite="true" />
   </cf:case>
   <cf:case value="3">
      <set name="attributes.processDate"   value="#dateFormat(dateAdd('m',36,now()),'dd/mm/yyyy')#"    overwrite="true" />
   </cf:case>
   <cf:defaultcase>
      <set name="attributes.processDate"   value="#dateFormat(dateAdd('m',12,now()),'dd/mm/yyyy')#"    overwrite="true" />
   </cf:defaultcase>
</cf:switch>

All we are doing here is checking for a licenceType variable attributes.licenceType, from this the switch statement calls the correct case statement and sets a variable called attributes.processDate. We then set a defaultcase statement which will catch a licenceType that doesn't matche the case statements we've setup. Nice and clean.


 

Related Blog Entries

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.