{"id":137,"date":"2007-12-30T21:31:36","date_gmt":"2007-12-31T04:31:36","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/crystal-reports-xi\/7-2-simple-data-types\/"},"modified":"2010-11-17T18:14:52","modified_gmt":"2010-11-18T01:14:52","slug":"7-2-simple-data-types","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/7-2-simple-data-types\/","title":{"rendered":"7.02 Simple Data Types"},"content":{"rendered":"<h2>Simple Data Types<\/h2>\n<p>Crystal syntax supports the standard data types that we expect in a language: number, Boolean, currency, string, date and time.<\/p>\n<p>         <b>Table 7-1. Data Type Default Values<\/b><\/p>\n<table border=\"1\">\n<tr>\n<th>Crystal Data Type<\/th>\n<th>Basic Data Type<\/th>\n<th>Default Value<\/th>\n<\/tr>\n<tr>\n<td>NumberVar<\/td>\n<td>Number<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>CurrencyVar<\/td>\n<td>Currency<\/td>\n<td>$0<\/td>\n<\/tr>\n<tr>\n<td>BooleanVar<\/td>\n<td>Boolean<\/td>\n<td>False<\/td>\n<\/tr>\n<tr>\n<td>StringVar<\/td>\n<td>String<\/td>\n<td>&#8220;&#8221;<\/td>\n<\/tr>\n<tr>\n<td>DateVar<\/td>\n<td>Date<\/td>\n<td>Date(0,0,0) &#8211; The Null Date value 00\/00\/00<\/td>\n<\/tr>\n<tr>\n<td>TimeVar<\/td>\n<td>Time<\/td>\n<td>No default value. Null.<\/td>\n<\/tr>\n<tr>\n<td>DateTimeVar<\/td>\n<td>DateTime<\/td>\n<td>No default value. Null.<\/td>\n<\/tr>\n<\/table>\n<p>Notice that rather than have a large number of numeric data types such as integer, double, etc., there is simply a single data type called NumberVar. There is no need to worry about whether the number is fractional or what its largest possible value is. One data type handles all situations.<\/p>\n<p>The CurrencyVar data type is treated the same as a NumberVar data type with a few exceptions:<\/p>\n<p>Currency can only have two decimal places. If assigned a number with more than two decimal places, it rounds up to the nearest penny.<\/p>\n<p>Currency automatically gets formatted as a monetary value. This eliminates the overhead of having to format the variable whenever it gets printed.<\/p>\n<p>Since Currency is a different data type, it must be converted to a number to be used in mathematical assignments using non-currency variables. See the section &#8220;Converting Data Types&#8221; for more information.<\/p>\n<p>Strings use the double quote, &#8220;, to specify a string literal. A character is represented by a string of length one. Referencing a position within a string is Base 1. Thus, if you want to refer to the first character in a string, you would use an index of 1. The maximum length of a string constant is 65,534 characters. Information on using the built-in string functions is in Chapter 6.<\/p>\n<p>         <code_Single>\/\/Demonstrate assigning a string constant to a variable<\/code_Single><br \/>\n         <code_Single>Local StringVar Title;<\/code_Single><br \/>\n         <code_Single>Title := &#8220;This is a string&#8221;;<\/code_Single><\/p>\n<p>Dates are a little unusual in that there are three different data types available. The DateVar type can only store a date and the TimeVar type can only store a time. It&#8217;s preferable to use these data types if you don&#8217;t need both values stored in a variable. If you do need both types in the same variable, use the DateTimeVar type. To assign a constant to a DateTimeVar , use the Date() function. You can use a variety of formats to pass the date to the function.<\/p>\n<p>         <code_Single>\/\/Show different ways of assigning a date to a variable<\/code_Single><br \/>\n         <code_Single>Local DateVar MyBirthday;<\/code_Single><br \/>\n         <code_Single>MyBirthday := Date(#5\/23\/1968#);<\/code_Single><br \/>\n         <code_Single>MyBirthday := Date(1968, 5, 23);<\/code_Single><br \/>\n         <code_Single>MyBirthday := Date(&#8220;May 23, 1968&#8221;);<\/code_Single><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Simple Data Types Crystal syntax supports the standard data types that we expect in a language: number, Boolean, currency, string, date and time. Table 7-1. Data Type Default Values Crystal Data Type Basic Data Type Default Value NumberVar Number 0 CurrencyVar Currency $0 BooleanVar Boolean False StringVar String &#8220;&#8221; DateVar Date Date(0,0,0) &#8211; The Null [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,1],"tags":[],"class_list":["post-137","post","type-post","status-publish","format-standard","hentry","category-chapter-7-programming-with-crystal-syntax","category-crystal-reports-xi","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/137","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=137"}],"version-history":[{"count":1,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/137\/revisions"}],"predecessor-version":[{"id":1432,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/137\/revisions\/1432"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}