Introduction

Language Structure

IB Statements

File System

Comet 32 Runtime

Index

LENGTH statement

Syntax: LENGTH length

(or)

LENGTH length.precision

Discussion: The LENGTH statement defines the length of string variables and the length and precision of numeric variables in the current Internet Basic program.

The Internet Basic compiler recognizes two formats for the LENGTH statement. The first format defines the length of string variables. The length parameter must be an integer from 1 to 254. This value indicates the maximum number of characters that may be stored in subsequent string variables. All string variables must be defined at a specific length. There is no system-supplied default value.

The second format includes a decimal point and the precision for numeric variables. The maximum length is 16, while the maximum precision is 15. Without a numeric LENGTH statement, the system- supplied default value is 8.2 (i.e., the field will store eight digits, two of which will be located to the right of the decimal point).

Setting the proper field length is extremely important. If the length is set too small, characters or digits will be truncated (i.e., data will be lost).

For example, if a string field is defined with a length of 10, but more than ten characters are moved to that field, characters following the tenth one will be truncated.

For numeric fields, truncation can occur on the left and right side of the field. For example, if a numeric field is defined with a length of 4.0, it can store values up to 9999. However, a higher value will result in truncation on the left side of the field.

Similarly, unless defined for rounding, numeric fields can be truncated on the right side of the decimal point. For an unrounded numeric field defined with a length and precision of 4.2, any value past the second decimal place will be truncated. For more information on rounding, see the ROUND statement.

In all cases of truncation, truncation occurs without warning of any kind.

Also see COMMON and LOCAL.

Example 1:
LENGTH 1.0
LOCAL DATA

(or)

LENGTH 1.0 & LOCAL DATA
This example shows the minimum length for a numeric variable. In this case, the variable named DATA is defined with a length of one digit and a precision of zero digits. Thus, this field can store integers only in the range -9 through 9 (i.e., a single digit).
Example 2:
LENGTH 8.2
LOCAL DATA

(or)

LENGTH 8.2 & LOCAL DATA
Here, the variable named DATA is defined with a length and precision of 8.2 (coincidentally, the default length and precision value). Thus, it can store up to six digits to the left of the decimal point and two digits to the right.
Example 3:
LENGTH 1
LOCAL FLAG$

(or)

LENGTH 1 & LOCAL FLAG$
Here, the string variable named FLAG$ is defined with a length of one character.
Example 4:
LENGTH 254
LOCAL MEMO$

(or)

LENGTH 254 & LOCAL MEMO$
The string variable named MEMO$ is defined with the maximum possible length 254. This variable can store up to 254 characters of data.