See Also: Type Conversion Functions, Data Types. Functions and Constants
The Cast function returns a variable of the specified type that is the best conversion from the original variable.
Specified type
Cast( {Var}, {Type} )
Where:
{Var} can be any variable, but not an expression or a constant value
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
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
The difference between Convert and Cast apply primarily to data-overflow situations such as changing an integer with a large value to a short. When a number doesn't fit you get an error with Convert and not with Cast. Strings are special. When you cast or convert from a string they do the same thing, which is to not raise data-range errors. However, if the format of your string is invalid, you get an error with Cast or Convert.