Page 1 of 1

Date into Database

PostPosted: Mon Feb 11, 2008 2:06 pm
by zyzix
Hello there!

I've just bought OrbForms Designer and build upon the (great!) Survey example my database application. I've added new fields, dropdowns etcetera. BUT it looks like i don't get the hang of the "date" functions. I wan't to add two Buttons: "Start" and "Stop". Both Buttons should do exactly the same: Write the actual date and time into the database. I even don't know how to display the date. Is there actually an example how to do this ? Thank you for your support. - zyzix

Re: Date into Database

PostPosted: Mon Feb 11, 2008 11:05 pm
by nmc
Try:

Date dbDate;
...
<assign value from your db to dbDate>
...
alert(dbDate.date());

docs: library reference / System / Date / date

Re: Date into Database

PostPosted: Tue Feb 12, 2008 2:03 pm
by zyzix
I've put that into the handler for pushStart and declared the date dbdate but somehow, nothing happens. No Build failure or something similar, i'm very beginner in PocketC (usually Develop in Delphi). Can you explain the <assign value from your db to dbDate> part a little bit more ? Thank you. - zyzix

Re: Date into Database

PostPosted: Wed Feb 13, 2008 12:42 am
by nmc
The following code is untested:

Code: Select all
Database db;
Date startDate;
DBRecord rec;

if (db.open("test", true)) {
   if (db.getrec(0, &rec, true)) {
      rec.read(&startDate, typeof(startDate), 1);
      rec.close();
      alert(startDate.date());
   }
   db.close();
}


Put this in your handler and replace "test" with the actual name of your (existing) database.

Re: Date into Database

PostPosted: Wed Feb 13, 2008 9:41 am
by zyzix
Hello there nmc!

First of all, thank you for your patience : ) I've added the part into the handler, but i'm getting
Code: Select all
cast required between incompatible types

in this line
Code: Select all
if (db.getrec(0, &rec, true)) {


i've modified it so that i could compile, but then on the PALM, following Message appears: Func:pushStart.onselectRecord must be created/opened first ...so i think i'm on the wrong way..

Re: Date into Database

PostPosted: Wed Feb 13, 2008 2:42 pm
by Percival
Try removing the & from &rec

Code: Select all
if (db.getrec(0, rec, true)) {

Re: Date into Database

PostPosted: Wed Feb 13, 2008 4:00 pm
by zyzix
Thank you both very much, works now : )