Home All Groups Group Topic Archive Search About
Author
22 Mar 2006 6:09 PM
DRBarkley
Hi all,

VB6 SP5:

It is my understanding that two UDTs can not be compared directly.

    If UDT1 <> UDT2 Then... ' error

So you would have to check each element individually to compare them.

    If UDT1.Prop1 <> UDT2.Prop1 Or UDT1.Prop2 <> UDT2.Prop2 . . .

This could get rediculous for a large UDT.

Is there a faster way to compare them?

Is each UDT contiguous in memory so some lower level mem compare could be
done?

Thanks,

DRBarkley

Author
22 Mar 2006 6:26 PM
Tony Proctor
It depends on what the fields are. If there are arrays or variable-length
strings then all the data is not in one contiguous memory area. Also, even
if the fields were all contiguous then they would have to be "naturally
packed", with no padding bytes, otherwise the aggregate memory may contain
uninitialised regions.

If you use VarPtr() to get the base address of 2 UDTs, be sure to use LenB()
to get the true byte length, and not Len()

    Tony Proctor

Show quoteHide quote
"DRBarkley" <David.NOSPAMBarkley@L-3NOSPAMCom.com> wrote in message
news:eQJbVvdTGHA.736@TK2MSFTNGP12.phx.gbl...
> Hi all,
>
> VB6 SP5:
>
> It is my understanding that two UDTs can not be compared directly.
>
>     If UDT1 <> UDT2 Then... ' error
>
> So you would have to check each element individually to compare them.
>
>     If UDT1.Prop1 <> UDT2.Prop1 Or UDT1.Prop2 <> UDT2.Prop2 . . .
>
> This could get rediculous for a large UDT.
>
> Is there a faster way to compare them?
>
> Is each UDT contiguous in memory so some lower level mem compare could be
> done?
>
> Thanks,
>
> DRBarkley
>
>
Author
22 Mar 2006 8:13 PM
Mike D Sutton
Show quote Hide quote
> It is my understanding that two UDTs can not be compared directly.
>
>     If UDT1 <> UDT2 Then... ' error
>
> So you would have to check each element individually to compare them.
>
>     If UDT1.Prop1 <> UDT2.Prop1 Or UDT1.Prop2 <> UDT2.Prop2 . . .
>
> This could get rediculous for a large UDT.
>
> Is there a faster way to compare them?
>
> Is each UDT contiguous in memory so some lower level mem compare could be
> done?

Without the availability of a simple memcmp() function and due to VB's structure padding, personally I would simply
create a function that takes the two structures and returns a boolean if all the fields match.  It may not be as
convenient as simply using the equals operator, but it's pretty simple to code and wouldn't require you to get your
hands dirty with memory manipulation or the idiosyncrasies of VB's UDTs.
This also gives you the opportunity to be a little more flexible with your comparison such as case insensitive
comparison of strings for example.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
22 Mar 2006 9:07 PM
DRBarkley
Show quote Hide quote
"Mike D Sutton" <ED***@mvps.org> wrote in message
news:uMwvG0eTGHA.1576@tk2msftngp13.phx.gbl...
> > It is my understanding that two UDTs can not be compared directly.
> >
> >     If UDT1 <> UDT2 Then... ' error
> >
> > So you would have to check each element individually to compare them.
> >
> >     If UDT1.Prop1 <> UDT2.Prop1 Or UDT1.Prop2 <> UDT2.Prop2 . . .
> >
> > This could get rediculous for a large UDT.
> >
> > Is there a faster way to compare them?
> >
> > Is each UDT contiguous in memory so some lower level mem compare could
be
> > done?
>
> Without the availability of a simple memcmp() function and due to VB's
structure padding, personally I would simply
> create a function that takes the two structures and returns a boolean if
all the fields match.  It may not be as
> convenient as simply using the equals operator, but it's pretty simple to
code and wouldn't require you to get your
> hands dirty with memory manipulation or the idiosyncrasies of VB's UDTs.
> This also gives you the opportunity to be a little more flexible with your
comparison such as case insensitive
> comparison of strings for example.
> Hope this helps,
>
>     Mike

Thanks Mike and Tony,

I thought as much.  That memcmp() is exactly what I was hoping existed.
But, it sounds like messing with padding is more of a hassle than it's
worth.

I have always gone the function route, but wanted to make the process as
fast as possible, since there is a lot of serial communication going on,
too.

I appreciate your responses,

DRBarkley