Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

8.05 Simple Data Types

Simple Data Types

Basic syntax supports the standard simple 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. There is no need to worry about whether the number will use a decimal point or what its largest value is.

The Currency data type is treated the same as a Number data type with a few exceptions. They are listed below:

  • Currency can only have two decimal places. If assigned a number with more than two decimal places, it will round up to the nearest penny.
  • Currency automatically gets formatted as a monetary value. This eliminates the overhead of always you having to format the variable whenever it gets printed.
  • 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 “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 the next chapter.

‘Demonstrate assigning a string constant to a variable
Dim Var As String
Var = "This is a string"

Dates are a little unusual in that there are three different data types available. The Date type can only store a date and the Time type can only store a time. It’s preferable to use these data types if you don’t need both values stored in a variable. If you do need both types in the same variable, use the DateTime type. Designate a DateTime constant by surrounding it with the # sign.

Dim MyBirthday As DateTime
MyBirthday = #5/23/1968#