Error in reading data file QB64
Error in reading data file QB64
(OP)
Dear Qbasic friends,
I am new to this group, I just use the qbasic for my research calculation because it is very easy to write the codes. Now I need your help with data file reading. I downloaded a data file which contains only numbers separated with TAB not the space, each line has 10 numbers, the first line likes 1 2 3 4 5 6 7 8 9 10, the second line likes 11 12 13 14 15 16 17 18 19 20, ......
the input statement is INPUT #1, a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10). However, it only reads the first number from each line, i.e, it only read 1 and 11....
I tested a data file with numbers separated by space created by Notepad, it works well, it will not work if the numbers are separated by tabs.
I cannot change the original data file. So please help me to solve the problem, maybe an easy fix.
I really appreciate your help.
Peter
I am new to this group, I just use the qbasic for my research calculation because it is very easy to write the codes. Now I need your help with data file reading. I downloaded a data file which contains only numbers separated with TAB not the space, each line has 10 numbers, the first line likes 1 2 3 4 5 6 7 8 9 10, the second line likes 11 12 13 14 15 16 17 18 19 20, ......
the input statement is INPUT #1, a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9), a(10). However, it only reads the first number from each line, i.e, it only read 1 and 11....
I tested a data file with numbers separated by space created by Notepad, it works well, it will not work if the numbers are separated by tabs.
I cannot change the original data file. So please help me to solve the problem, maybe an easy fix.
I really appreciate your help.
Peter
RE: Error in reading data file QB64
I tried to read the file line by line and parse numbers from every line by locating the TAB-characters and the numbers, i used INSTR and MID$ functions for this..
Here is the example, which you can try:
text_file.bas
CODE
The program first creates the matrix A of random numbers and prints it.
Then it writes the matrix A into text file with the structure:
NUM TAB NUM TAB .. TAB NUM CR LF
like this:
my_data.txt
CODE
At end it reads the data from the file into matrix B and prints it.
RE: Error in reading data file QB64
Is it working for you ?
RE: Error in reading data file QB64
Thank you for your great help. It really solved the problem.
Peter
RE: Error in reading data file QB64
you are welcome