|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Comparing UDTsVB6 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 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 > >
Show quote
Hide quote
> It is my understanding that two UDTs can not be compared directly. Without the availability of a simple memcmp() function and due to VB's structure padding, personally I would simply> > 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? 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/
Show quote
Hide quote
"Mike D Sutton" <ED***@mvps.org> wrote in message structure padding, personally I would simplynews: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 > 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. comparison such as case insensitive> This also gives you the opportunity to be a little more flexible with your > comparison of strings for example. Thanks Mike and Tony,> Hope this helps, > > Mike 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
Help with disconnected recordset!
question -- close adodb connection inside dll Hidden treasures... vb6 and iso 8601 date format CommonDialog sets Windows Default Printer - is Mike Williams out there? click on a menu error making function call with multiple parameters to dll Error creating Oracle object WebBrowser vs Pdf.ocx ADODB Recordsets into Array |
|||||||||||||||||||||||