Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Darkbasic Data saving

Author
Message
compter geak 1966
17
Years of Service
User Offline
Joined: 22nd Feb 2008
Location:
Posted: 22nd Feb 2008 23:56
Yeah If any one knows how to setup multi recordset on a single file with deleting the file every time I add a new recordset
Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 23rd Feb 2008 01:13
File command set. Go to the input section of the help files.

Seriously, how do you make the little blue text come up below your message?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 24th Feb 2008 04:10 Edited at: 24th Feb 2008 04:11
Quote: "setup multi recordset on a single file with deleting the file every time I add a new recordset "


WITH deleteing? There are no random access files in DBC per se, but you can store and retrieve a record set in the form of an array pretty easily. Use SAVE ARRAY and LOAD ARRAY:



Enjoy your day.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 24th Feb 2008 05:02
Quote: "how to setup multi recordset on a single file with deleting the file every time"


If you mean saving the contents of more than one array into the same file then you cannot do it with Save Array and Load Array because the filename is one of the command's parameters. (Each time you save an array with the same filename it will delete the one you last saved).

Assuming (like Latch) that you meant 'without deleting' rather than 'with', you have two options.

1. Have all your data in a single multi-dimensioned array and use Load/Save Array. The down side is that you cannot mix data types - ie the array must be integer, float or string only. However if you use string arrays they can be used to store all types - converting from one to the other when loading/saving.

Ie: Dim Database$(MaxRecords,NumFields)

If you created the array with Dim Database$(1000,12) this would allow up to 1000 records, each with 12 fields (using fields element zero for the field name for example).

2. Use Open To Read/Write and load/save the contents of all arrays manually in For..Next loops. The advantage of this is that you can save any combination of string and numeric arrays before closing the file.

Whichever method you use, as Latch says, there's no random file access in DBC - only sequential. So, when you open a file for writing, the file cannot already be there and if it does, you have to delete it first.

Not losing data is a simple case of checking when the program first runs to see if a data file already exists - using File Exist() - and if it does, load the contents into memory.

You add the new data to what is already in memory and just before saving it you delete the existing file(s).

A good place to start for answers to most beginners questions:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

(See Tutorial 4 - File Access).

TDK_Man

Login to post a reply

Server time is: 2025-06-04 01:50:41
Your offset time is: 2025-06-04 01:50:41