Sver
Full Member
Posts: 145
|
Post by Sver on Mar 6, 2019 6:52:19 GMT -5
Is there a limit for inputcsv ?
a$, b$,.....25 ?
|
|
|
Post by Rod on Mar 6, 2019 7:48:07 GMT -5
A quick test proves not.
open "test.csv" for input as #readFile inputcsv #readFile, a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn print a,b,mm,nn close #readFile end
It might be that what ever you are creating the csv file with is breaking the line at 25 characters. Look at the asc value of the characters in your file and see if there is a hidden CRLF or LF
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Mar 7, 2019 10:03:06 GMT -5
Hello Rod.
Ok. I 'll make a csv/txt file , "a","b","c", ....to 32, (export raf database) then,.. i want to import/read the same file to the same raf database. It works, no problem, but ,..
When i change a for r in excel between export and import, then i goes wrong. I my case changing a letter in excel is no problem, but when i use more then 25 items/column then import goes wrong??
What is a hidden CRLF or LF ??
|
|
|
Post by Rod on Mar 7, 2019 10:30:12 GMT -5
Ok I am not really understanding your explanation. Whatever you are doing in excel you are creating rows of 25 columns with line breaks in between. A line break is flagged by inserting the control characters CR and LF (Carriage Return Line Feed) into the data stream. These control characters are never displayed to you. Typically they make the displayed text return to the left, CR and drop down a line, LF.
data data data data...CRLF data data data data...CRLF
If it is an excel table you are exporting it will have a CRLF at the end of every row. They are asc characters chr$(13) and chr$(10)
Probably best if you show us some sample data then we can code a solution.
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Mar 8, 2019 7:19:54 GMT -5
record=1
a$="John"
b$="Mi:c:k:e:y"
jj$="Robert"
'----
open "test.csv" for output as #readFile
print #readFile,_
chr$(34)+a$+chr$(34)+","+chr$(34)+b$+chr$(34)+","+chr$(34)+c$+chr$(34)+","+_
chr$(34)+d$;chr$(34) +","+chr$(34)+e$+chr$(34) +","+chr$(34)+f$+chr$(34) +","+_
chr$(34)+g$+chr$(34) +","+chr$(34)+h$+chr$(34) +","+chr$(34)+i$+chr$(34) +","+_
chr$(34)+j$+chr$(34) +","+chr$(34)+k$+chr$(34) +","+chr$(34)+l$+chr$(34) +","+_
chr$(34)+m$+chr$(34) +","+chr$(34)+n$+chr$(34) +","+chr$(34)+o$+chr$(34) +","+_
chr$(34)+p$+chr$(34) +","+chr$(34)+q$+chr$(34) +","+chr$(34)+r$+chr$(34) +","+_
chr$(34)+s$+chr$(34) +","+chr$(34)+t$+chr$(34) +","+chr$(34)+u$+chr$(34) +","+_
chr$(34)+v$+chr$(34) +","+chr$(34)+w$+chr$(34) +","+chr$(34)+x$+chr$(34) +","+_
chr$(34)+y$+chr$(34) +","+chr$(34)+z$+chr$(34) +","+chr$(34)+aa$+chr$(34)+","+_
chr$(34)+bb$+chr$(34) +","+chr$(34)+cc$+chr$(34) +","+chr$(34)+dd$+chr$(34)+","+_
chr$(34)+ee$+chr$(34) +","+chr$(34)+ff$+chr$(34) +","+chr$(34)+hh$+chr$(34)+","+_
chr$(34)+ii$+chr$(34) +","+chr$(34)+jj$+chr$(34)
close #readFile
end
'second part
record=1
open "test.csv" for input as #readFile
open "db.dat" for random as #db len=3075
field #db,_
20 as a$,_
20 as b$,_
20 as c$,_
20 as d$,_
20 as e$,_
10 as f$,_
100 as g$,_
255 as h$,_
100 as j$,_
100 as k$,_
100 as l$,_
100 as m$,_
100 as n$,_
100 as o$,_
100 as p$,_
100 as q$,_
100 as r$,_
100 as s$,_
10 as t$,_
100 as u$,_
100 as v$,_
100 as w$,_
100 as x$,_
100 as y$,_
100 as z$,_
100 as aa$,_
100 as bb$,_
100 as cc$,_
100 as dd$,_
100 as ee$,_
100 as ff$,_
100 as gg$,_
100 as hh$,_
100 as ii$,_
100 as jj$,
'--------------------------
while eof(#readFile) = 0
inputcsv #readFile, a$,b$,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh.ii,jj$
'--------
put #db, record
record=record+1
wend
'-------
close #readFile
close #db
end
The code works good. Create a txt/csv file and import it to db.dat. When i changed the value of field in test.csv with excel and want to import it again to db.dat , it goes wrong. (value in the wrong fields or never ending writing to db.dat
I must be something with a strange value or passed end of file.
|
|
|
Post by Rod on Mar 8, 2019 9:06:29 GMT -5
Ok I was confused for a while, you are writing the file as CSV then reading it back in and saving it as a RAF. Why? Why not save it as a RAF in the first place? I am not sure I understand why you are using Excel and you need to explain how you are importing and exporting the data to and from excel. Your code works and creates the CSV that can be read back in Given there are no errors the RAF PUT seems to be working as well. So its back to what is excel doing to the data? Also there is a known bug that if you PUT to record 0 Liberty will write a huge empty file and seem stuck while doing so. So check that the record pointer is not 0. There is a good tutorial on the LBPE alycesrestaurant.com/lbpe/files.html
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Mar 8, 2019 11:39:57 GMT -5
Sometimes you get data from other programs or you give it to their. They don't work with .dat files. Then import and export is important.
The best way to test it, is to do a export and import with the same file. Liberty works ok. I doubt about my code. (forgot something) Excel is changing data. I have to compare it.
Thanks !
|
|
|
Post by Rod on Mar 8, 2019 12:47:12 GMT -5
Think less about .csv .dat .txt and be sure you know how the data is actually formatted within these loose/abused file descriptors
|
|