SEEK with INPUT for variable length strings
#1
Code: (Select All)
OPEN "data.txt" FOR OUTPUT AS #1
OPEN "data.ndx" FOR RANDOM AS #2 LEN = 4 'one long variable in size

DIM ndx AS LONG 'that long variable I mentioned above
DIM text AS STRING 'and a random length string
DIM count AS LONG 'and a counter for which element we want

DO
    ndx = LOF(1) + 1
    PUT #2, , ndx
    READ text$
    PRINT #1, text$
LOOP UNTIL text$ = "EOD"
CLOSE #1
OPEN "data.txt" FOR INPUT AS #1
'now we have a data file that we can use input with and read any record out of at will
DO
    INPUT "Which record would you like to retrieve =>"; count
    IF count = 0 THEN SYSTEM
    GET #2, count, ndx
    SEEK #1, ndx
    INPUT #1, text
    PRINT "That record was: "; text
LOOP

1

DATA one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve
DATA thirteen,fourteen,fiveteen,sixteen,seventeen,eighteen,nineteen,tenteen,eleventeen,twelveteen,EOD
Reply


Messages In This Thread
SEEK with INPUT for variable length strings - by SMcNeill - 02-07-2023, 07:28 PM



Users browsing this thread: 3 Guest(s)