Combined DATA rows

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
David.B
Newbie
Posts: 1
Joined: Mon Mar 03, 2014 6:45 am

Combined DATA rows

Post by David.B » Mon Mar 03, 2014 8:31 am

My problem is folloving:
2 of data rows groups with 5 number in each row,for example
data 3,5,8,6,2
data 4,2,7,9,4
data5,1,7,9,3
data 6,3,1,4,2,
to be combined with
data 12,15,33,43,45
data 11,18,20,31,35
data 14,16,45,34,89
data 17,19,23,45,57
so that printing will be 16 rows ,all combined with eachather
3 5 8 6 2 12 15 33 43 45
3 5 8 6 2 11 18 20 31 35
e.t.c.
Can somebody help me?
(excuse for my English)
thanks

User avatar
burger2227
Veteran
Posts: 2359
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: Combined DATA rows

Post by burger2227 » Mon Mar 03, 2014 3:28 pm

You can put DATA anywhere in the program and READ each value consecutively or READ specific labeled data fields by using line labels with RESTORE. Only problem is that it starts at the beginning of each field so you may have to read some more than once.

Code: Select all

FOR i = 1 TO 5
  READ dat 'can read first data w/o restore
  PRINT dat;
NEXT
RESTORE datafield2
FOR i = 1 TO 5
  READ dat 'can read second data block with restore
  PRINT dat;
NEXT


datafield1:
DATA 3,5,8,6,2
DATA 4,2,7,9,4
DATA 5,1,7,9,3
DATA 6,3,1,4,2,

'to be combined with
datafield2:
DATA 12,15,33,43,45
DATA 11,18,20,31,35
DATA 14,16,45,34,89
DATA 17,19,23,45,57
I'll let you figure out the rest...
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Re: Combined DATA rows

Post by Mentat » Thu Mar 06, 2014 12:51 am

Hint: Combining the lines would be easier if you somehow could access the data like an array . . .
For any grievances posted above, I blame whoever is in charge . . .

semih
Newbie
Posts: 2
Joined: Fri Mar 07, 2014 7:12 pm

Re: Combined DATA rows

Post by semih » Sat Mar 08, 2014 2:34 pm

1. group data --> data1.txt
2. group data --> data2.txt

open data1.txt as #1
open data2.txt as #2
open new.txt as #3
do until eof(1) or eof(2)
  line input #1, a$
  line input #2, b$
  c$=a$+b$
  print #3,c$
loop
close

etc

Post Reply