Skip to main content

valueType

valueType ( expression : any ) : integer

ParameterTypeDescription
expressionanyExpression whose resulting value to be tested
ResultintegerData type number

Description

The valueType command returns the type of the value resulting from the evaluation of the expression you passed as parameter.

The command returns a numeric value that can be compared with one of the following constants provided by Qodly:

ConstantValue
kBlob30
kBoolean6
kCollection42
kDate4
kInteger9
kNull255
kObject38
kPicture3
kNumber1
kString2
kTime11
kUndefined5
kVariant12

This command is designed to return the type of a scalar expression, i.e. the value stored in or returned by the expression parameter. In particular, it can be applied to the following Qodly expressions:

  • object properties (emp.name),
  • collection elements (myCol[5]).
note

Numerical object properties are always considered number values:

var o : object
var vType : integer
o = newObject("value",42)
vType = valueType(o.value) //vType = kNumber

Example 1

You want to handle the various possible types of an object property value:

switch
:(valueType(o.value) == kNumber)
//handle a numeric value
:(valueType(o.value) == kString)
//handle a string
:(valueType(o.value) == kObject)
//handle a sub-object
...
end

Example 2

You want to sum up all numeric values in a collection:

var col : collection
var colSum : number
col = newCollection("Hello",20,"World2",15,50,currentDate,true,10)
for(i,0,col.length-1) //-1 since collections start at 0
if(valueType(col[i]) == kNumber)
colSum = colSum+col[i]
end
end