### Automatic type conversions

Generally in Seagate 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:

    Dim postalCode as String
    'Error- assigning a Number value to a String variable
    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:

- Number to Currency
- Date to DateTime
- Simple type to Range value of the same underlying simple type

For example, the following assignments are correct:

    Dim cost As Currency
    'Same as: cost = CCur (10)
    cost = 10
    Dim orderDate As DateTime
    'Same as: orderDate = CDateTime (1999, 9, 23, 0, 0, 0)
    orderDate = CDate (1999, 9, 23)
    Dim aRange As Number Range
    'Same as: aRange = 20 To 20
    aRange = 20
    Dim aRangeArray () As Number Range
    'Same as :
    'aRangeArray = Array (10 To 10, 20 To 25, 2 To 2)
    aRangeArray = Array (10, 20 To 25, 2)

Note: The opposite conversions are not allowed. For example:

    Dim num As Number
    num = 5 + CCur (10) 'Error
    'OK- convert to Number type using the CDbl function
    num = CDbl (5 + CCur (10))

5 is converted to CCur (5) and added to CCur (10) to make CCur (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.

Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com