AS (explicit type conversion)

Top  Previous  Next

 

<expression> AS <type>

 

AS

Used for explicit casting

type

signature of a type

Although Clarion performs type conversions implicitly, there are times when you may need to perform an explicit conversion. The AS and TRYAS keywords are used to perform explicit conversions between compatible types.

 

AS and TRYAS operators are used for explicit casting. TRYAS uses Clarion Type Conversion rules for the casting of value-types, but throws an exception if the casting is impossible, but AS will return null in this case.

 

Both AS and TRYAS operators try to cast the specified expression to the given type. The difference between these operators is the following:

 

• TRYAS throws an exception if the casting is impossible, but AS return null in this case.

• AS operator doesn’t accept value-types for <type>

 

Also, TRYAS uses Clarion Type Conversion rules for the casting of value-types.

 

Example:

 

A LONG

 CODE

 A = ('10' & '20') TRYAS LONG   !  Casting to long

 

See Also: TRYAS (Explicit type conversion)