I am trying to compare two DBDATE variables and it does not work as hoped.
' console - dbdate.eba
/*
TYPE DBDATE
WORD year
WORD month
WORD day
ENDTYPE
*/
OPENCONSOLE
DBDATE aDate, bDate
aDate.day = 21
aDate.month = 8
aDate.year = 2008
bDate.day = 1
bDate.month = 8
bDate.year = 2008
DO
bDate.day = bDate.day + 1
PRINT Str$(bDate.day)+"/"+Str$(bDate.month)+"/"+Str$(bDate.year)
UNTIL bDate = aDate
PRINT "Press Q to quit"
DO: UNTIL INKEY$ = "Q"
CLOSECONSOLE
END
The PRINT statement is to check the bDate value is incrementing until bDate = aDate.
Not possible this way?
No you can't compare one UDT with another. Just make a quick function, using AND...
sub comparedates(DBDATE a, DBDATE b),int
return (a.day = b.day) AND (a.month = b.month) AND (a.year = b.year)
endsub
Then you can use the subroutine in your loop:
DO
bDate.day = bDate.day + 1
PRINT Str$(bDate.day)+"/"+Str$(bDate.month)+"/"+Str$(bDate.year)
UNTIL comparedates(aDate,bDate)
For larger UDT types you can use the C runtime function memcmp...
declare cdecl extern memcmp(pointer a, pointer b,int len),int
DO
bDate.day = bDate.day + 1
PRINT Str$(bDate.day)+"/"+Str$(bDate.month)+"/"+Str$(bDate.year)
UNTIL memcmp(aDate,bDate, LEN(DBDATE)) = 0
memcmp returns 0 when both are identical. In the case of a date structure it is faster using the AND construct in the first example, as it will return quickly if the days are different.
Paul.
Thanks you.
I will use that function to compare the DBDate UDT vars.