Microsoft KB Archive/88479

= How to Compare User-Defined Type Variables in Basic PDS =

Article ID: 88479

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1
 * 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

-



This article was previously published under Q88479



SUMMARY
The relational operators (=, <>, and so on) do not support the comparison of user-defined type variables. You can compare user- defined type variables by converting the variables to strings, then comparing the strings. Use PEEK, VARPTR, and CHR$ to convert a user-defined type variable to a string.



MORE INFORMATION
If you attempt to compare user-defined type variables using the relational operators, you will receive a &quot;Type mismatch&quot; error.

The following example program demonstrates how to compare user-defined type variables using relational operators. Before comparison, the variables are converted to strings. DECLARE FUNCTION type2str$ (t AS ANY)

TYPE myType f1 AS STRING * 2 f2 AS SINGLE END TYPE

DIM x AS myType DIM y AS myType

x.f1 = &quot;ab&quot; x.f2 = 2 y = x

IF type2str(x) = type2str(y) THEN PRINT &quot;x = y&quot; ELSE PRINT &quot;x <> y&quot; END IF

y.f1 = &quot;ba&quot; IF type2str(x) > type2str(y) THEN PRINT &quot;x > y&quot; ELSE PRINT &quot;x <= y&quot; END IF

' ' type2str converts a user-defined type variable to a string. ' FUNCTION type2str$ (t AS myType) DEF SEG = VARSEG(t)  ' In case the variable is in a dynamic array. FOR i% = 0 TO LEN(t) - 1 s$ = s$ + CHR$(PEEK(VARPTR(t) + i%)) NEXT DEF SEG type2str = s$ END FUNCTION

Additional query words: QuickBas BasicCom 7.00 7.10 4.00 4.00b 4.50

Keywords: KB88479

-

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

© Microsoft Corporation. All rights reserved.