Cast

See Also: Type Conversion Functions, Data Types. Functions and Constants

Purpose

The Cast function returns a variable of the specified type that is the best conversion from the original variable.

Return Type

Specified type

Syntax

Cast( {Var}, {Type} )

Where:

Example

Procedure TestCast

    UInteger u

    Real r

 

    move 3.1415 to r

    // Move Real r to Unsigned Integer u, decimals will drop off

    move (Convert(r, UInteger)) to u

 

    Send Info_Box u "Result"

End_Procedure

Example

Cast differs from Convert in that it will not report conversion errors in data overflow situations. Cast will, however, still report an error if a string contains a value that cannot be properly converted to another type. For example:

Procedure TestCast

    String s

    Integer i

 

    Move ",.1" to s

    Move (Cast(s, Integer)) to i

End_Procedure

Notes