CLASTRING (.NET fixed-length string)

Top  Previous  Next

 

 

 

 

 

|       length       |

 

 

label

CLASTRING

(

| string constant |

)

[,DIM( )] [,NAME( )] [,EXTERNAL] [,DLL]

 

 

 

|       picture       |

 

[,STATIC] [,THREAD] [,PRIVATE] [,PROTECTED]

CLASTRING

A character string.

 

Format: A fixed number of bytes.

Size: 4MB

 

length

A numeric constant, variable, or expression that defines the number of bytes in the CLASTRING. CLASTRING variables not initialized with length are treated as a standard .NET variable length STRING..

string constant

The initial value of the STRING. The length of the STRING (in bytes) is set to the length of the string constant.

picture

Used to format the values assigned to the STRING. The length is the number of bytes needed to contain the formatted STRING.

DIM

Dimension the variable as an array.

NAME

Specify an alternate, "external" name for the field.

EXTERNAL

Specify the variable is defined, and its memory is allocated, in an external library. Not valid within FILE, QUEUE, or GROUP declarations.

DLL

Specify the variable is defined in a .DLL. This is required in addition to the EXTERNAL attribute.

STATIC

Specify the variable's memory is permanently allocated.

THREAD

Specify memory for the variable is allocated once for each execution thread. Also implicitly adds the STATIC attribute on Procedure Local data.

PRIVATE

Specify the variable is not visible outside the module containing the CLASS methods. Valid only in a CLASS.

PROTECTED

Specify the variable is not visible outside base CLASS and derived CLASS methods. Valid only in a CLASS.

 

CLASTRING declares a fixed-length character string. The memory assigned to the CLASTRING is initialized to all blanks.

 

CLASTRING is the near equivalent to the WIN32 STRING variable type. The one difference is that the CLASTRING data type supports null values. An attempt to use CLASTRING with null value raises an exception (NullReferenceException).

For example:

 

Str  CLASTRING(10)

 CODE

 Str=null

 IF( Str=null)

  MESSAGE('String contains null')

  MESSAGE(Str)   !raise an exception

 END

 

 

You can declare CLASTRING types of variable size to the compiler. Restrictions are the same as for variable-size arrays: declarations are available in the procedure or routine local scope only, and all variables used in the expression must be known at the time of the variable’s creation. See Also: Variable Size Declarations

In addition to its explicit declaration, all CLASTRING variables are also implicitly declared as CLASTRING(1),DIM(length of string). This allows each character in the CLASTRING to be addressed as an array element. If the CLASTRING also has a DIM attribute, this implicit array declaration is the last (optional) dimension of the array (to the right of the explicit dimensions).

You may also directly address multiple characters within a CLASTRING using the "string slicing" technique. This technique performs similar action to the SUB function, but is much more flexible and efficient (but does no bounds checking). It is more flexible because a "string slice" may be used on both the destination and source sides of an assignment statement and the SUB function can only be used as the source. It is more efficient because it takes less memory than individual character assignments or the SUB function.

To take a "slice" of the CLASTRING, the beginning and ending character numbers are separated by a colon (:) and placed in the implicit array dimension position within the square brackets ([]) of the CLASTRING. The position numbers may be integer constants, variables, or expressions. If variables are used, there must be at least one blank space between the variable name and the colon separating the beginning and ending number (to prevent PREfix confusion). Position is zero-based in Clarion#, meaning that zero (0) represents the first character position.

Example:

Name        CLASTRING(20)                      !Declare 20 byte name field

ArrayString CLASTRING(5),DIM(20)               !Declare array

Company     CLASTRING('SV Corporation')        !The software company - 20 bytes

Phone       CLASTRING(@P(###)###-####P)        !Phone number field - 13 bytes

ExampleFile FILE,DRIVER('Clarion')             !Declare a file

Record       RECORD

NameField     CLASTRING(20),NAME('Name')       !Declare with external name

            END

           END

 CODE

 NameField = 'Tammi'                          !Assign a value

 NameField[5] = 'y'                           ! change fifth letter

 NameField[5:6] = 'ie'                        ! and change a "slice"

                                              ! the fifth and sixth letters

 ArrayString[1] = 'First'                     !Assign value to first element

 ArrayString[1,2] = 'u'                       !Change first element 2nd character

 ArrayString[1,2:3] = NameField[5:6]          !Assign slice to slice