Compare user defined data types 
Author Message
 Compare user defined data types

How to compare two user defined data types?
This causes a Type Mismatch:

type mytype
       Age as long
       name  as string
end type

dim type1 as mytype
dim type2 as mytype

' assign some values here
type1.age=7
type1.name="Jack"
type1.age=6
type1.name="Wesley"

if type1=type2 then'<<<<Causes type mismatch!

--
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
remove REPLYTO from my e-mail address to reply.
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*



Fri, 27 Jul 2001 03:00:00 GMT  
 Compare user defined data types
Since there is no operater overloading in VB, the only way to compare UDDT is
to create function which does it.  For your example:

Private Function TestEqual (mtEqual1 as mytype, mtEqual2 as mytyme) as Boolean
Dim x as Integer
x=0

if mtEqual1.Age = mtEqual2.Age then
 x = x + 1
end if
if mtEqual1.Name = mtEqual2.Name then
 x = x + 1
end if

if x=2 then
 TestEqual =True
else
 TestEqual = False
end if

End Function

-Dan



Fri, 10 Aug 2001 03:00:00 GMT  
 Compare user defined data types
To speed up your code (especially when you have a great number of fields in
your UDT) you can use this:

Private Function TestEqual (mtEqual1 as mytype, mtEqual2 as mytyme) as
Boolean
TestEqual = False
If mtEqual1.Age = mtEqual2.Age Then
    If mtEqual1.Name = mtEqual2.Name Then
        TestEqual = True
    End If
End If
End Function

To function ends as soon as a difference is found, so it's better to begin
with fields with a high probability to be different (not "sex" for
instance).

Philippe



Sat, 11 Aug 2001 03:00:00 GMT  
 Compare user defined data types

Quote:
>Since there is no operater overloading in VB, the only way to compare UDDT is
>to create function which does it.  For your example:

>Private Function TestEqual (mtEqual1 as mytype, mtEqual2 as mytyme) as Boolean
>Dim x as Integer
>x=0

>if mtEqual1.Age = mtEqual2.Age then
> x = x + 1
>end if
>if mtEqual1.Name = mtEqual2.Name then
> x = x + 1
>end if

>if x=2 then
> TestEqual =True
>else
> TestEqual = False
>end if

>End Function

>-Dan

You could also store each UDT, using LSET, in two instances of a third
UDT consisting of a byte array sufficiently large to hold your UDTs,
and then compare these byte by byte.

I've just posted a message which basically requests a vb function to
allow UDT to be stored in strings. This might allow you to compare
strings.



Tue, 14 Aug 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Q: variant data type with user defined data type

2. Compile error: User-defined data type not defined!

3. comparing two user defined types

4. Comparing User-Defined Types

5. Sorting and Comparing Elements in Arrays of User Defined Types

6. Comparing instances of the same user-defined type?

7. Type mismatch on user defined data type

8. User Control - User-defined type not defined

9. VB4: Help: data-alignment in user defined data types

10. Help: data-alignment in user defined data types

11. Passing Array or a user defined data type as a parameter to a storedprocedure in Oracle

12. HELP user defined data types

 

 
Powered by phpBB® Forum Software