CVT() Function - Pixel, Character, and Semicharacter Unit Conversion

Syntax

CVT(unit_value,conversion_type{,ERR=lineref})

Description

For BBj-specific information, see CVT() Function - BBj.

The CVT() function converts units between pixel, character, and semicharacter formats.

Parameter

Description

unit_value

An integer that indicates the value of the unit to convert.

conversion_type

An integer that indicates the type of unit conversion, identified in the table below.

ERR=lineref

Branch to be taken if an error occurs during execution.

Values for conversion_type Parameter

The following identifies the options for the conversion_type parameter. Truncating functions ignore any extraneous pixels or semicharacters, while rounding functions round any pixel or semicharacter remainder that is a half-unit or larger up to the next unit.

Value

Converts from

Converts to

Remainder

0

Horizontal pixels

Horizontal semicharacters

Truncated

1

Vertical pixels

Vertical semicharacters

Truncated

2

Horizontal pixels

Horizontal characters

Truncated

3

Vertical pixels

Vertical characters

Truncated

4

Horizontal pixels

Horizontal semicharacters

Rounded

5

Vertical pixels

Vertical semicharacters

Rounded

6

Horizontal pixels

Horizontal characters

Rounded

7

Vertical pixels

Vertical characters

Rounded

8

Horizontal semicharacters

Horizontal characters

Rounded

9

Vertical semicharacters

Vertical characters

Rounded

10

Horizontal semicharacters

Horizontal characters

Truncated

11

Vertical semicharacters

Vertical characters

Truncated

12

Horizontal semicharacters

Pixels

N/A

13

Vertical semicharacters

Pixels

N/A

14

Horizontal characters

Horizontal semicharacters

N/A

15

Vertical characters

Vertical semicharacters

N/A

16

Horizontal characters

Pixels

N/A

17

Vertical characters

Pixels

N/A

Vertical and Horizontal Character and Semicharacter Dimension Definitions

The following defines vertical and horizontal characters and semicharacters listed in the previous table:

Character

Definition

Horizontal Character

Width of the average character in the system font.

Horizontal Semicharacter

One-fourth the width of an average character in the system font.

Vertical Character

Height of the system font characters.

Vertical Semicharacter

One-eighth the height of the system font.

Example

The following example converts horizontal pixels to horizontal semicharacters and vertical pixels to vertical semicharacters:

rem define a string template for the WININFO control sub-string
tdef$="class:u(1),type:u(1),flags:u(4),id:u(2),x:u(2),y:u(2),w:u(2),"
tdef$=tdef$+"h:u(2),reserved:u(2),sibling:u(2),name:c(10*=0),"
tdef$=tdef$+"title:c(10*=0)"
dim control$:tdef$
rem window_data$ is a string returned by WININFO
rem start is the offset to the current control sub-string
control$=window_data$(start)
rem WININFO always returns pixel values for a control's x, y, width and height
rem convert the horizontal pixels to horizontal semi-chars rounding any remainder
semi_char_x=cvt(control.x,4)
semi_char_w=cvt(control.w,4)
rem convert the vertical pixels to vertical semi-chars rounding any remainder
semi_char_y=cvt(control.y,5)
semi_char_h=cvt(control.h,5)

See Also

Functions - Alphabetical Listing