Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
load data from file as data of separate databases
#1
quickbasic 4.5 question please.

Is it possible to load data from a file where some of the data is in one part , (14, 18, and 23) and the rest of the data is in another part (44,66,77, and 99)

I know the program below won't work because I cant figure out how to read data from (scoreSmile . qbasic wants to start at the beginning of file. But that won't work.

CLS
DIM age(3) AS INTEGER
DIM score(14) AS INTEGER

OPEN "data.txt" FOR INPUT AS #1
DO UNTIL i = 3
i = i + 1
INPUT #1, age(i)
LOOP
CLOSE #1
PRINT age(i);


OPEN "data.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
i = i + 1
INPUT #1, score(i)
LOOP
CLOSE #1
PRINT score(i);
end

The data file is as follows:

age:
14
18
23

misc. comments and information here
gljglrkgjnrlikg
rkrgjakgljgkl
rgakgjkrgjrg


score:

44
66
77
99
Reply
#2
Do the records in your file contain the three types of data? That is, does your file have records that contain the age, the comments, and then the score?
Example: Is each data record designed something like this:
* AGE in positions 1 to 3
* COMMENTS in positions 5 to 19
* SCORE in positions 20 to 22

If the records are something like that, then you can read each record and extract the AGE, COMMENTS, SCORE on one pass through the file. Then maybe your program could be:
Code:
open "data.txt" for input as #1
do while not eof(1)
     line input #1,d$
     age$ = left$(d$,3)
     cmt$ = mid$(d$,5,15)
     scr$ = mid$(d$,20,3)
     ' Then if you want to print each:
     print age$;space$(2);scr$
loop
system
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)