Microsoft KB Archive/66424

= LSET Can Assign One TYPE Variable to a Different TYPE =

Article ID: 66424

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBASIC 4.0b, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBasic 4.5 for MS-DOS, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q66424



SUMMARY
The LSET statement can assign a variable dimensioned as one user-defined TYPE to a variable dimensioned as a different user-defined TYPE. This can be useful in assigning string TYPEs that differ in length.

This information applies to Microsoft QuickBasic versions 4.00, 4.00b, 4.50 for MS-DOS, to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2.



MORE INFORMATION
Direct (or LET) assignment of differing TYPEs correctly gives a &quot;Type Mismatch&quot; error, because direct assignment requires identical TYPEs.

LSET allows you to assign any user-defined TYPE variable to any other user-defined TYPE variable. However, you must be cautious not to mismatch numeric elements (INTEGER, LONG, SINGLE, or DOUBLE) (or CURRENCY in Basic PDS only) when using LSET assignment of record TYPE variables, or else you will assign spurious values.

Note: If the user-defined TYPEs are of different lengths, LSET copies only the number of bytes in the shorter of the two variables. For example, if you LSET a 10-byte variable into a 2-byte variable, LSET will copy only 2 bytes of the larger variable into the smaller variable. If you LSET the 2-byte variable into the larger one, it will copy only the first 2 bytes of the larger variable.

In the following code example, LSET assigns a variable of one TYPE to a variable of another TYPE.

Code Example
TYPE Type1 FirstName AS STRING * 10 LastName AS STRING * 12 END TYPE TYPE Type2 FullName AS STRING * 22 END TYPE DIM Var1 AS Type1 DIM Var2 AS Type2

Var1.FirstName = &quot;John&quot; Var1.LastName = &quot;Smith&quot; LSET Var2 = Var1  ' Assigns record variables of differing TYPEs PRINT Var2.FullName END The output is as follows:   John      Smith

Additional query words: QuickBas BasicCom

Keywords: KB66424

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.