The problem is DmGetNextDatabaseByTypeCreator returns errNone (aka 0) 
when successful, and a non-zero value when there are no (more) matching 
databases.  So the if statement and while loop are using the logical 
opposite of what you want.

Somehow I missed that one when I went through the "bible."  My copy has 
the exact same mistake in it.

- PK

Richard Coutts wrote:
> I'm writing my first database code.  I copied this simple function out of
> the Palm OS Programming Bible, but its not returning.  Or, it wasn't until I
> made it quit when the count rose to 10000.  It seems so straight forward,
> I'm at a loss what's going on.  Any insight would be greatly appreciated.
> 
> Thanks!
> Rich
> 
> // The function call looks like this:
> Int16 count = CountDBs('DATA', 'PCAD');
> 
> // Count the number of Databases
> Int16
> CountDBs(UInt32 type, UInt32 creator) {
>     // (code from "Bible" pg. 385
>     DmSearchStateType searchState;
>     Int16 count = 0;
>     UInt16 cardNo;
>     LocalID dbID;
> 
>     if (DmGetNextDatabaseByTypeCreator(true, &searchState,
>         type, creator, false, &cardNo, &dbID)
>     {
>          do {
>              count++;
>         } while (count < 10000 && DmGetNextDatabaseByTypeCreator(false,
> &searchState,
>             type, creator, false, &cardNo, &dbID));
>     }
>     return count;
> }
> 
> 
> 
> 




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to