{"id":1004,"date":"2008-10-12T19:57:29","date_gmt":"2008-10-13T02:57:29","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/books\/?p=1004"},"modified":"2008-10-12T20:00:20","modified_gmt":"2008-10-13T03:00:20","slug":"811-choose-and-switch","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/811-choose-and-switch\/","title":{"rendered":"8.10 Choose() and Switch()"},"content":{"rendered":"<h2>The Choose() Function<\/h2>\n<p>The Choose() function returns a value chosen from a list of values. The value returned is determined by an index that is passed to the function. This function is like a shortcut for the If statement and the Select Case statement. You can use it when the range of possible values is relatively small and sequential.<\/p>\n<p>The first parameter is an index representing which item to return. The remaining parameters are the items to choose from. The index range starts at 1 (it&#8217;s not zero based). If the index is a value that is greater than the number of items passed, the default value for the appropriate data type is returned (e.g. zero for numbers, &#8220;&#8221; for strings). This function can return any data type except for an array. As expected, each item in the list must be of the same data type.<\/p>\n<p>The syntax for the Choose() function is as follows:<\/p>\n<p><code>Var = Choose(index, value1, value2, value3, ...)<\/code><\/p>\n<h2>The Switch() Function<\/h2>\n<p>The Switch() function is also like a shortcut for the If statement and the Select Case statement. The parameters are grouped in pairs. The first parameter is an expression to test and the second parameter is a result value that is returned if the expression is true.<\/p>\n<p>The syntax for the Switch() function is as follows:<\/p>\n<p><code>Var = Switch(condition1, result1, condition2, result2, ....)<\/code><\/p>\n<p>What makes this unique from the If and Select Case statements is that every parameter is evaluated before a result is returned from the function. This can have good or bad results depending upon your needs. The result can be bad because there could be a performance issue if you are passing time-intensive functions as parameters or it could result in an error being raised. It can be good if you want to force various functions to be called prior to returning a value. This function can return any data type except for an array. The data types of each result must be the same.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Choose() Function The Choose() function returns a value chosen from a list of values. The value returned is determined by an index that is passed to the function. This function is like a shortcut for the If statement and the Select Case statement. You can use it when the range of possible values is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,40],"tags":[],"class_list":["post-1004","post","type-post","status-publish","format-standard","hentry","category-chapter-8-learning-basic-syntax","category-crystal-reportsnet-2008","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/1004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=1004"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/1004\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=1004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=1004"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=1004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}