Convert
See Also: Type Conversion Functions, Data Types, Functions and Constants
Purpose
The Convert function returns a variable of the specified type that is the best conversion from the original variable. Note that Type Conversion Functions, such as Integer or String for a known target data type, are more commonly used.
Return Type
Specified type
Syntax
Convert( {Var}, {Type} )
Where:
- {Var} can be a variable of any data type, but not an expression or a constant value.
- {Type} is the name of a data type, for example, Number.
Example
Procedure testConvert
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
Notes
-
The difference between Convert and Cast applies 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.
-
If a conversion error occurs, error 4381 will be reported.