April 19, 2024, 11:12:17 AM

News:

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


Saving and retrieving diary items from a file

Started by AdrianFox, January 06, 2010, 04:52:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

I'll swallow my pride and ask a very basic question.  This is something I'm doing as a 'learning' project but I seem to have got stuck at a very basic stage.

I've created a simple diary program using the controlex d1,"SysMonthCal32","",0,0,600,400,@border,@exclientedge,1 for a calendar and extracting the date
with ccGetCurSel d1,1,m,d,y.

So far, although it 'works' adequately, I use the ghastly and inelegant method of saving each diary entry to a separate file identified with the a date string.  Of course, I should really be retrieving and updating my entries from a single file.

I thought this might be possible with a binary file using PUT and GET.   While I can save entries this way, I don't understand how to retrieve them.  I've been trying to use the date info (d, my, y) to create the record number, but this clearly doesn't work.  Also, each subsequent entry overwrites the file, so I'm not sure whether I should be opening the file for Write or Append.   On the other hand, perhaps using a binary file is not the way to do this.

Do I really need to create a database file to save and retrieve my entries?  Had a quick look at this, especially with the thought of using a CSV file, but have so far tried to stick with a simpler solution.

As I'm doing this as a learning process,  I'm not asking how to do it;  I'd just be grateful to know  whether I should be using a simple file  or using a database to do what I want to do.

Thanks.
:-\

Adrian Fox

LarryMc

As I see it you have 2 options.
Either create a database that is indexed on the date and contains a memo field to hold your text regardless of how long or short it is.

Or, use my xml class to store your info in an xml files with a date field.

The latter would be the harder of the 2 for you to learn from scratch.

For the former you could use the addressbook.eba as the "go-by".

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

peterpuk

Hi Adrian,

If you are comfortable coding with the database functions, I would use a database. Since you want the data to be sorted/indexed by a specific field, the work is done for you using the database functions.

You could use a binary/random access file in which each record is of a set length, but you would need to allow a couple of extra fields to use as pointers to the next and previous records (these fields are updated when you insert a new entry). You are basically linking records in order of date. Tricky stuff and really not flexible if you want to do more with the data later.

Determining how you save and store data is quite an important part of an application, and there are many considerations.
Peter

AdrianFox

Thanks Larry and Peter.
I guess I will have to bite the bullet and get to grips with the database stuff.  Paul's address book will be a real help to get me started.
:)
Adrian Fox

aurelCB

Adrian...
I just wonder why you chose dialog instead of window as frame form.
Maby becose i almost never use dialogs i my programs ::).
I think that window is better option for all tasks.
However...
I suggest you that you store your data in binary file as simpliest option...

all best
Aurel