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 / Use of the DATA command?

Author
Message
EsteemDE
19
Years of Service
User Offline
Joined: 5th Aug 2005
Location:
Posted: 25th Aug 2005 00:09
I dont understand how the DATA command works. I read the short description in the help file but I still dont understand it. I understand that it stores actual data and you can use any type of data. I also can see you can store multiple datas in one line using a comma. But how do you read a specific data you input into your EXE?

The manual says use the read command but the example shows how to read a specific variable and not something from a DATA statement itself.

So yeah, whats the use of them and how do you access a certain DATA?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Aug 2005 00:27
The items in a DATA statement are pulled out of the DATA line using READ. For example:



You must make sure that the type of variable in the READ matches the type in the DATA statement and that there is always enough data items in the list for READ to read in.

You cannot read say just the 4th value - you have to read all the items in and ignore those you don't want (the first 3).

As you read values in, an internal 'counter' remembers what you have read so far. So if there are 10 items of data and you read 4 in, then next READ will fetch item 5 and carry on from there.

You do however have the RESTORE command. This 'resets' the counter so that READ will start at the first data item next time.

RESTORE also has an optional version RESTORE LABEL which let's you reset the counter to labels positioned between the data lines.

Using it, you could have your data for different things on seperate lines like this:

Red:
Data 3,6,1,3,4,5,2,6,4,5

Green:
Data 6,4,2,7,9,3,2,4,3,5

Blue:
Data 4,6,4,3,6,7,8,3,2,2

If you wanted to read in the 10 items on the second Data line, you would do a

RESTORE Green:

before using the READ loop. If you wanted to read in the 10 items of the first Data line, you would use:

RESTORE Red:

...and so on.

TDK_Man

EsteemDE
19
Years of Service
User Offline
Joined: 5th Aug 2005
Location:
Posted: 25th Aug 2005 02:35 Edited at: 25th Aug 2005 02:37
Ok thanks a lot. You said you can "ignore" the first 3, to read the 4th, if there were only 4 things in the data statement. How would I ignore those?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Aug 2005 02:49
This would be the easiest way:



However, with this method there's a chance that you try to read in past the end of the data line and cause an error.

The more sensible method would be to load all the data values in and place them into an array. From there, you can access any of the values directly:



After doing this, the fourth item is in MyArray(4), the 10th item in MyArray(10) and so on.

TDK_Man

EsteemDE
19
Years of Service
User Offline
Joined: 5th Aug 2005
Location:
Posted: 25th Aug 2005 06:18 Edited at: 25th Aug 2005 06:27
So if I had a DATA statement that was like yours:

Blue:
Data 4,6,4,3,6,7,8,3,2,2

I would do this to read it and make an aray:



That correct?????
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Aug 2005 14:51 Edited at: 25th Aug 2005 14:53
Yup - you got it!

If there's only one set of data, then you don't need the label Blue - that's for when you need to use RESTORE, which you wouldn't need if you are only going to load all data statements in once.

After that For..Next loop your ArrayBlue array would be full, and any further READ's would use the values off the next data line(s).

So, you could have three arrays, three data lines and three For..Next loops:



And, as they are being stored in an array, you don't need to re-read them again, so RESTORE isn't required and therefore neither are the labels. (You may want to keep them in just to remind you what each data line is used for though)...

TDK_Man

Login to post a reply

Server time is: 2024-11-27 18:34:45
Your offset time is: 2024-11-27 18:34:45