March 28, 2024, 07:30:06 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Compare UDT's

Started by billhsln, January 03, 2011, 10:17:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

January 03, 2011, 10:17:17 PM Last Edit: January 03, 2011, 10:18:54 PM by billhsln
Here is some quick and dirty code to compare 2 UDT's against each other.  This is where both variables use the same UDT.

SUB CompUDT(c:POINTER,p:POINTER,l:INT),INT
DEF i:INT
FOR i = 0 TO l-1
IF #<char>c <> #<char>p THEN RETURN 0
c++
p++
NEXT i
RETURN 1
ENDSUB


Sample:

TYPE NTXCLC_format
DEF MemberNo:INT
DEF FName[22]:ISTRING
DEF MName[22]:ISTRING
DEF LName[22]:ISTRING
DEF Suffix[5]:ISTRING
DEF Addr1[42]:ISTRING
DEF Addr2[42]:ISTRING
DEF City[32]:ISTRING
DEF State[12]:ISTRING
DEF Zip[12]:ISTRING
DEF HomePhone[17]:ISTRING
DEF CellPHone[17]:ISTRING
ENDTYPE

DEF Current:NTXCLC_format
DEF Previous:NTXCLC_format

' Code to load data into Current.xxx or Previous.xxx

IF CompUDT(Current,Previous,BASELEN(Current)) = 1
MESSAGEBOX w1,"Current = Previous","Info"
ELSE
MESSAGEBOX w1,"Current <> Previous","Info"
ENDIF

END


I hope this will be of use to some one.  This probably could be done better in ASM, but I do not know how to program in ASM.

Bill
When all else fails, get a bigger hammer.

LarryMc

January 03, 2011, 11:39:52 PM #1 Last Edit: January 03, 2011, 11:45:18 PM by Larry McCaughn
Bill
Just out of curiosity did you try:
DEF Current:NTXCLC_format
DEF Previous:NTXCLC_format
'..... set values

if #<NTXCLC_format>Current = #<NTXCLC_format>Previous
print 'equal"
endif


It seems like I did that once but I may have dreamed it. :D
EDIT:  I think I did it when all the elements were numbers.
LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

Larry, I gave it a try and it does not work.  I wish it did, would make my program a little easier to follow.

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

Bill

I played around with this and everything seemed to work.
But I was restating the program each time which might make a difference.
May have to do a rtlzeromemory thing when changing an istring variable.
openconsole
type a
istring z[10]
int a
int b
endtype

a b,c

b.a=2
b.b=3
b.z="abc"

c.a=2
c.b=3
c.z="abc"
if b=c
print "equal"
else
print "not equal"
endif

print "any key to close"
waitcon
closeconsole
end


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

My full blown type is about 4449 chars.  When I make both the same and change something in the 'Active' field and then do the check it still comes up equal.  So far, my little subroutine still works on the compare.

Thanks,
Bill

My full type:

TYPE NTXCLC_format
DEF MemberNo:INT
DEF FName[22]:ISTRING
DEF MName[22]:ISTRING
DEF LName[22]:ISTRING
DEF Suffix[5]:ISTRING
DEF NewsLetter:CHAR
DEF AssocMember[32]:ISTRING
DEF Addr1[42]:ISTRING
DEF Addr2[42]:ISTRING
DEF City[32]:ISTRING
DEF State[12]:ISTRING
DEF Zip[12]:ISTRING
DEF HomePhone[17]:ISTRING
DEF CellPHone[17]:ISTRING
DEF WorkPhone[17]:ISTRING
DEF FaxPhone[17]:ISTRING
DEF NatNo:INT
DEF NatDate[12]:ISTRING
DEF Sponsor[32]:ISTRING
DEF EMailMain[42] :ISTRING
DEF EMailAssoc[42]:ISTRING
DEF WebSite[52]:ISTRING
DEF SendNat:CHAR
DEF RecordUpdated[12]:ISTRING
DEF MiscNotes[82]:ISTRING
DEF Active:CHAR
DEF ChildName[22,4]:ISTRING
DEF CarNo[30]:INT
DEF CarYear[30]:INT
DEF CarMake[30]:CHAR
DEF CarModel[42,30]:ISTRING
DEF YearNo[30]:INT
DEF YearComment[72,30]:ISTRING
ENDTYPE
When all else fails, get a bigger hammer.