TYPE SET statement

Purpose

Assign the value of a User-Defined Type or string expression into another User-Defined Type or string variable.

Syntax

TYPE SET mainvar = {typevar | stringexpr$} [USING ustring_expression]

Remarks

TYPE SET is primarily designed to assign the value of a User-Defined Type (UDT) to a different class of User-Defined Type.  Additionally, TYPE SET can be used to assign a string expression (stringexpr$) to a UDT or a string variable.

USING

Character positions remaining after the assignment are filled (padded) in mainvar as directed by the optional USING clause.

If the assigned data is shorter than the string or type variable mainvar, it is padded on the right with the first character of the USING string expression ustring_expression, or binary zeros ($NUL) if not specified.

If the USING string is null (zero length or empty), any trailing padding character positions are left unchanged in mainvar.  This is similar to the ABS option in the LSET statement.  To perform right-justification, use the RSET statement.

See also

CSET, CSET$, LSET, LSET$, RSET, RSET$, TYPE/END TYPE

Example

TYPE udt1

  x AS STRING * 12

  y AS LONG

  z AS INTEGER

END TYPE

 

TYPE udt2

  a(1 TO 18) AS BYTE

END TYPE

 

FUNCTION PBMAIN

  DIM u1 AS udt1

  DIM u2 AS udt2

 

  u1.x = "ABC"

  TYPE SET u2 = u1

  a$ = CHR$(u2.a(1), u2.a(2), u2.a(3))

 

  TYPE SET u2 = "1" USING "2"

  b$ = CHR$(u2.a(1), u2.a(2), u2.a(3))

END FUNCTION

Result

a$ contains "ABC"

b$ contains "122"