Chapter 7 - Writing Formulas
Crystal Reports gives you the option to program formulas in either Crystal syntax or Basic syntax. This chapter teaches you how to program with both Basic syntax and Crystal syntax. Dozens of code samples show you exactly how to write code that you can put in your own reports today.
Crystal Report Data Types
Simple Data Types
Crystal Report's Basic syntax supports the standard typical data types that we expect in a language: Boolean, Number, Currency, String, DateTime, Date, and Time.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 Number (Crystal syntax uses NumberVar). There is no need to worry about whether the number is fractional or what its largest value is. One data type handles all cases.
The Currency data type is treated the same as a Number data type with a few exceptions:
- Currency can only have two decimal places. If assigned a number with more than two decimal places, it rounds up to the nearest penny.
- Currency automatically gets formatted as a monetary value. This eliminates the overhead of you having to format the variable whenever it gets printed.
- Since Currency is a different data type, it must be converted to Number to be used in mathematical assignments using non-currency variables. See the section "Converting Data Types' for more information.
Strings use the double quote, ", 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 Basic syntax built-in string functions is in Chapter 6.
‘Demonstrate assigning a string constant to a variable
Dim Var As String
Var = "This is a string"
Dim MyBirthday As DateTime
MyBirthday = #5/23/1968#
To read all my books online, click here for the Crystal Reports ebooks.