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 / Question regarding the DATA statement

Author
Message
Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 29th Dec 2007 23:00
It's me again!
I have come to the chapter in the Hands-on volume which lets you create a classical game: Hangman!
Fun to do and very interesting. A lot of neat tips and tricks are embedded into this little exercise, but I've stumbled upon something I don't really get.

Here's the code:


This is a little 'test-driver' to see if the function performs correctly.
At first the 'RESTORE' command is not present in the code.
Without RESTORE the program only prints one or two chosen words on-screen if you run it, instead of the expected 10.

The explanation in the book says that this is so because without RESTORE all the values in the DATA statements have been used in one or two runs. Why is this??


Yskonyn - (Ploughing through Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 30th Dec 2007 06:40 Edited at: 30th Dec 2007 06:44
Quote: "
RESTORE
This command will reset the DATA statement pointer...
"


if you don't reset the pointer (via the restore command) it (the pointer) stays where it read the last data statement. if the variable num = 20 (19+1) the first time you run it, the pointer will be at the end. when you go to read data again, there won't be anything left for it to read. hence the need to move the pointer back to the start/first data statement.

Virtual Nomad
AMD XP 1800+ (~1.6 Ghz) / 1.5 GB RAM
ATI Radeon 8700LE 128 MB / Windows XP
HeavyAmp
17
Years of Service
User Offline
Joined: 25th Oct 2006
Location: Castle in the Sky!
Posted: 30th Dec 2007 07:14
In my entry for the little book of source code comp I read all my words into an array and then choose a random word from that. Ill post the the code since It didn't win. Which is understandable since the user input is very shoddy .



Better to be dead, than to live your life afraid.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 30th Dec 2007 11:55
was gonna suggest using an array but didn't want Yskonyn to stray from the lesson he's currently following. keep at it, Yskonyn.

Virtual Nomad
AMD XP 1800+ (~1.6 Ghz) / 1.5 GB RAM
ATI Radeon 8700LE 128 MB / Windows XP
Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 30th Dec 2007 16:10
Thanks for the clarification!
So if you use a program to read the DATA statements, it functions as a virtual cursor which stays at its location unless you use RESTORE somewhere to make it jump to the beginning again?

hehe, indeed I have to stick to the exercise. Arrays are next on the list. Are Arrays easier to use than DATA statements?

Thanks again!


Yskonyn - (Ploughing through Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."
HeavyAmp
17
Years of Service
User Offline
Joined: 25th Oct 2006
Location: Castle in the Sky!
Posted: 30th Dec 2007 20:33
Quote: "Are Arrays easier to use than DATA statements?"


Not really easier but they are very useful.

Better to be dead, than to live your life afraid.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 31st Dec 2007 04:29 Edited at: 31st Dec 2007 04:35
yeah, you can call the pointer in this regard a sort of "virtual cursor", "book mark", "point of reference", etc.

also, your statement/understanding:
Quote: "
...use RESTORE somewhere to make it jump to the beginning again"


is a little too narrow in scope because, as the help file states, labels can be used with the restore command to establish "starting points", moving the pointer to A start point of your choice (not necessarily the first data statement) for subsequent data reads.

consider this example of the use of restore, with labels:



Quote: "Are Arrays easier to use than DATA statements?"


simple answer: no, but arrays provide a way to store, organize, manipulate, reference, handle, etc, data.

Virtual Nomad
AMD XP 1800+ (~1.6 Ghz) / 1.5 GB RAM
ATI Radeon 8700LE 128 MB / Windows XP
Yskonyn
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: Netherlands
Posted: 31st Dec 2007 13:21
Thanks Nomad! Very clear explanation!
On to Arrays! (It IS the next chapter)


Yskonyn - (Ploughing through Hands On DBP Programming Vol. 1)
"It's better to wish down here you were up, then to wish up there you were down."

Login to post a reply

Server time is: 2024-09-27 08:34:45
Your offset time is: 2024-09-27 08:34:45