$typed

Explicitly convert data to a specified data type.

$typed("DataTypeConverter(Value)")

$typed("Value")

vBoolean = $typed("$boolean(01)") ; returns F: value is string and begins with 0
vNumber = $typed("$number(01)")   ; returns 1
vString = $typed("$string(01)")   ; returns 01
vString = $typed("01")            ; returns 01

Parameters

  • DataTypeConverter—defines the target data type to be used when converting the value. One of $boolean, $clock, $date, $datim, $float, Snumber, $string, $syntax. if omitted, $string is assumed.
  • Value—data to be converted.

Return Values

Converted data.

Use

Allowed in all component types.

Description

The $typed function is used to ensure that data values are interpreted as being of a specific data type. For many data types, there is an explicit ProcScript function that can be used to perform this conversion. However, for data types String, Float, and Boolean, the only way to enforce this conversion is using the $typed function.

Data Type Conversion Functions
Using $typed Type-specific ProcScript Function Returns
$typed("$boolean(Value)")   Boolean
$typed("$clock(Value)") $clock(Value) Time type
$typed("$date(Value)") $date(Value) Date type
$typed("$datim(Value)") $datim(Value) DateTime type
$typed("$float(Value)")   Float type
$typed("$number(Value)") $number(Value) Number type
$typed("$string(Value)") Although there is a $string ProcScript function, it is used to convert XML entities to strings, not to convert data to String. Constant string type
$typed("$syntax(Value)") $syntax(Value) Syntax string type

The $typed function (and other data type conversion functions) can be used to construct typed lists for use in passing lists of parameters. For example, the activate/list command requires a typed list of parameters.

$string

The $string converter used in $typed should not be confused with $string ProcScript function. They have a different purpose and different syntax:

ProcScript Returns Explanation
$string("A & B") "A & B" The parameter is a string that contains an XML entity &, which the $string ProcScript function converts to an ampersand (&).
$typed($string("A & B")) "A & B" The parameter is the $string ProcScript function, which converts the XML entity.
$typed("$string(A & B)") "A & B" The parameter is a string containing the $string converter. It does not convert the XML entity, and just returns the literal string.
$typed("A & B") "A & B" The parameter is a string, so the default $string converter is assumed.

Typed List

For example, the following code generates a list with different values for 012345 depending on the data type:

variables
  string vList
endvariables

putitem vList, -1, $typed("$string(012345)")
putitem vList, -1, $typed("$boolean(012345)")  ; start with 0 yields F
putitem vList, -1, $typed("$boolean(12345)")   ; start with any other character yields T
putitem vList, -1, $typed("$float(012345)")
putitem vList, -1, $number(012345)
putitem vList, -1, $date(12-3-45)              ; requires valid input string
putitem vList, -1, $clock(012345)

;Result: vList = 012345;F;T;12345;12345;20450312;0000000001234500