Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the DATA and READ commands

Status
Not open for further replies.

sandmann999

Programmer
Apr 28, 2001
52
US
Can someone tell me how to access a certain piece of a DATA string?

For example, if I use the lines

RESTORE TEST
FOR Y = 1 TO 10
FOR X = 1 TO 10
READ INFO
PRINT INFO
NEXT
NEXT

TEST:
DATA 1,2,3,4,5
DATA 2,2,3,1,5
DATA 1,5,8,4,1
DATA 6,3,3,0,5
DATA 1,2,3,4,2

This code would access the data starting from the top left and read down to the bottom right.

What if I wanted to jump to the middle?
Like if I wanted these four variables:

DATA 1,2,3,4,5
DATA 2,2,3,1,5
____
DATA 1,5,|8,4|,1
DATA 6,3,|3,0|,5
-----
DATA 1,2,3,4,2

How would I just jump straight through the rest of the DATA to right there?
Any help would be great.

PS: I have a rather large DATA statement that can't really be broken up into smaller parts. If I were to put RESTORE statements to access the pieces I need, there are so many options, it would take hundreds of RESTORE statements.
It's about a 100 x 100 cube of data so just even cycling through the numbers to get the ones I want takes a while. I need a way to "skip" to where I want and access it that way.

Thanks!
 
Just a thought. Couldn't you put this data into a random access file, then you could access the info if you know the postion.
David Paulson


 
I've heard of random access files but I don't know how to use them. Would you be able to tell me how?

Thanks
 
DATA 1,2,3,4,5
DATA 2,2,3,1,5
DATA 1,5,8,4,1
DATA 6,3,3,0,5
DATA 1,2,3,4,2
'the following routine will read your data , create a random acces file named Myfile.dat and write this info to this new file.
ffile = freefile 'get a free file number
Open "Myfile.dat" for Random as #ffile len = 2
Field #ffile, 2 as dat$ 'This file is only going to contain one field which is an integer (integer is 2 bytes long)
For search = 1 to 25 'loop thru data
read info
get #ffile, search 'move to position of the file
rset dat$ = mki$(info)'convert contents of info to a type that can be stored in the file (microsoft binary format)
put #ffile, search 'write this record to the file
next search
close #ffile 'close the file

'lets open this file back up and read data in postion 10
ffile = freefile
open "Myfile.dat" for random as #ffile len = 2
field #ffile, 2 as dat$
get #ffile, 10
info = cvi(dat$) 'convert back to an integer
print info 'should print a 5
close #ffile


I'll let you choke on that for awhile.;-) Note this code was not tested and may contain a bug.
David Paulson


 
sandmann999:

If you don't want to create a seperate file you can always use a dimensionalized array to store your data. Consequentialy, you'll be eating up more memory if you have a VERY large program. Below is an example of how you can use the DIMensional array. I've coded it so that you should be able to grasp the concept.

--example code--

DIM Storage(100)
CLS
FOR DataLook = 1 TO 25
READ DataStored
Storage(DataLook) = DataStored
PRINT DataStored;
NEXT
PRINT "Here's your data block AS IS"
PRINT
PRINT
SLEEP 2

INPUT "Enter number of bit you want (Range 1-100) ", FindIt
IF FindIt <= 0 OR FindIt > 100 THEN END
PRINT
PRINT &quot;This is what is located at bit&quot;; STR$(FindIt); &quot;:&quot;
PRINT Storage(FindIt) 'Displays memory address value
PRINT
IF FindIt > 25 THEN
COLOR 12
PRINT
PRINT &quot;You received a zero cause your request&quot;
PRINT &quot;was larger than 25. When a DIM'd array&quot;
PRINT &quot;is called, it is initilized to zeros &quot;
PRINT &quot;(if the array is numeric) and to empty&quot;
PRINT &quot;strings (if the array is alphanumeric).&quot;
PRINT
COLOR 16
PRINT &quot;--MiggyD&quot;
PRINT
COLOR 7
END IF
END

TestLookup:
DATA 1,2,3,4,5
DATA 2,2,3,1,5
DATA 1,5,8,4,1
DATA 6,3,3,0,5
DATA 1,2,3,4,2


Hope this can help. Otherwise, good luck. Check your other posts too.
--MiggyD &quot;The world shrinks more and more with every new user online.&quot;
 
Sandmann999,

As you can see there are several approaches to your situation and I also have another one. You can maintain your data structure but you will need to break it up has you said you could before where you will need to branch off to each section. You As The Program Will Have To Tell Your Program Where To Branch Off To When You Need To Move To A Specific section and that's done using the RESTORE command.
The program would look something like this:
----------------------
RESTORE TEST
FOR Y = 1 TO 10
FOR X = 1 TO 10
READ INFO
PRINT INFO
NEXT
NEXT
PRINT,&quot;1 > Read First Database&quot;
PRINT, &quot;2 > Read Second Database&quot;
PRINT, &quot;3 > Read Third Database&quot;
INPUT &quot;Type Your Selection: &quot;,PICK
IF PICK=1 THEN RESTORE TEST
IF PICK=2 THEN RESTORE TEST2
IF PICK3 THEN RESTORE TEST3
REM ************************************************
REM You Would Now Have READ Start Reading Your Data
REM From This Point.
REM I Hope This Helps
REM ************************************************

TEST:
DATA 1,2,3,4,5
DATA 2,2,3,1,5
DATA 1,5,8,4,1
DATA 6,3,3,0,5
DATA 1,2,3,4,2

This code would access the data starting from the top left and read down to the bottom right.

What if I wanted to jump to the middle?
Like if I wanted these four variables:
TEST2:
DATA 1,2,3,4,5
DATA 2,2,3,1,5
TEST3: ____
DATA 1,5,|8,4|,1
DATA 6,3,|3,0|,5
TEST4: -----
DATA 1,2,3,4,2

How would I just jump straight through the rest of the DATA to right there?
Any help would be great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top