March 28, 2024, 03:41:51 AM

News:

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


Comparing DBDATE values

Started by Allan, August 20, 2008, 06:28:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Allan

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?

Ionic Wind Support Team

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.


Ionic Wind Support Team

Allan

Thanks you.

I will use that function to compare the DBDate UDT vars.