Ord Function

Applies to TestComplete 15.69, last modified on November 13, 2024

Returns the integer index of an ordinal value.

Declaration

Ord(Value) Parameters
Value [in] Required Variant
Result     Integer  

Description

Ordinal data types consist of a set of countable ordered values. That is, ordinal values can be counted one by one in a specific order and therefore each value has the corresponding integer index. Typical examples of ordinal values are integer numbers, characters and Boolean values.

The Ord function returns the index of the specified ordinal value. For instance, it can be used to get ASCII codes of characters.

Parameters

The function has one parameter:

Value

The ordinal value whose numeric index you want to get.

Return Value

An integer number that specifies the ordinal index of the Value:

  • If Value is an integer number, the function returns this value.

  • If Value is a string, the function returns the ASCII code of the first character in this string.

  • If Value is a Boolean, the function returns 1 if it is True, and 0 if it is False.

If Value is not of the ordinal type (for example, if it is a floating-point value), the function returns 0.

Example

The following example illustrates the Ord function result for various ordinal values.

DelphiScript

procedure Test;
begin
  Log.Message( Ord(123) );    // 123
  Log.Message( Ord(-42) );    // -42
  Log.Message( Ord('A') );    // 65
  Log.Message( Ord(' ') );    // 32
  Log.Message( Ord(true) );   // 1
  Log.Message( Ord(false) );  // 0
end;

See Also

DelphiScript - List of Supported Routines and Variables

Highlight search results