Xbasic
CONVERT_TYPE Function
Syntax
Output_Value as A = Convert_Type(A Source, C RequestedType)
Arguments
- SourceAny Type
A variable containing character, numeric, date, or logical data.
- RequestedTypeCharacter
The requested data type. The type can be any Xbasic type listed below:
- Type
- Description
- C
Character
- D
Date
- K
GUID
- L
Logical
- N
Numeric
- T
Date Time
- Y
Short Time
See Variable Data Types to learn more about Xbasic variable data types.
Returns
- Output_ValueAny Type
Returns the value of Source variable as the requested data type. If the requested type is not supported or doesn't exist, the returned value will be a Character value.
Description
Converts a value from one data type to another.
Discussion
CONVERT_TYPE() converts variables from one data type to another, preserving the data if possible.
? convert_type("yes", "L") = .T. ? convert_type(345, "C") = "345" ? convert_type(now(), "C") = "12/08/2018 02:32:17 27 am"
If the requested data type is not supported or invalid, CONVERT_TYPE() converts the value to a Character data type. For example:
' Converting to a dot variable "P" is not supported result1 = convert_type(.F., "P") ' Data returned as type "C": ? typeof(result1) = "C" ? result1 = "False"
See Also