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.

Newcomers DBPro Corner / Read and Data Statements

Author
Message
Merrie
18
Years of Service
User Offline
Joined: 18th Jan 2006
Location: PA
Posted: 16th Jan 2007 23:18
I am going through DBP book 1, soon to have 2 and I want to ask for more clerification on Read and Data, what would they be best to use for? Any examples would be appreciated.

--------------------------------------------
Dark Basic Pro | Windows XP |
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 17th Jan 2007 08:41
"Data" can be used for anything you want because it has the power to store strings and/or numbers. It can store a menu, inventory list, a drawing, planetary information, phone numbers, sprite information, anything that normal variables can store.

Check this example out:


Can you guess what the data will reveal before running it?
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Jan 2007 18:08 Edited at: 17th Jan 2007 18:10
To add to what Grog correctly said:

Read and data statements can be useful when you want information embedded in your exe so users can't easily get to it and meddle.

The down side is that if you need to alter any of the data, you have to supply a new exe file.

So, if frequent updates are likely, (and the data doesn't need to be hidden), you are better using an external data file and reading it in off disk. That way, updates can be distributed via a new smaller data file instead of the whole thing.

A typical example might be a game of hangman where all the words are in data statements at the end of the program. This would be a prime candidate for the external file method whereby adding new words would only need you to supply an updated words file.

As you can see, what Grog's example does is, starting at the first item, read each number from the data lines one at a time into a variable and use them.

Once all the data is read in, the next Read will fail, so you would need to use the Restore command to reset the pointer to a label - or alternatively, you could read all the data just once, but store it in arrays for future use.

TDK_Man

Merrie
18
Years of Service
User Offline
Joined: 18th Jan 2006
Location: PA
Posted: 19th Jan 2007 23:52
Thank you both, that cleared things up nicely.

--------------------------------------------
Dark Basic Pro | Windows XP |

Login to post a reply

Server time is: 2024-09-25 15:23:16
Your offset time is: 2024-09-25 15:23:16