Generally in Crystal Reports, values of one type cannot be used where values of another type are expected without explicitly supplying a type conversion function. For example:
Local StringVar postalCode; //Error- assigning a Number value to a String postalCode := 10025; //OK - use the type conversion function CStr //to create "10025" postalCode := CStr (10025, 0);
However, there are a few conversions that are made automatically:
For example, the following assignments are correct:
Local CurrencyVar cost; //Same as: cost := $10 cost := 10; Local DateTimeVar orderDate; //Same as: orderDate := CDateTime (1999, 9, 23, 0, 0, 0) orderDate := CDate (1999, 9, 23); Local NumberVar Range aRange; //Same as: aRange := 20 To 20 aRange := 20; Local NumberVar Range Array aRangeArray; //Same as : aRangeArray := [10 To 10, 20 To 25, 2 To 2] aRangeArray := [10, 20 To 25, 2];
Note The opposite conversions are not allowed. For example:
Local NumberVar num; num := 5 + $10; //Error //OK- convert to Number type using the CDbl function num := CDbl (5 + $10) //Could also use ToNumber
5 is converted to $5 and added to $10 to make $15. However, this Currency value cannot be automatically assigned to the Number variable num since automatic conversions from Currency to Number are not allowed. Similarly, functions accepting a Currency argument can be supplied a Number argument instead, and the Number argument will be converted to a Currency, whereas functions accepting a Number argument cannot be supplied a Currency argument without first explicitly converting the Currency to a Number using CDbl.
Variables | Simple Data Types | Range Data Types | Array Data Types