Author |
Topic: inputCSV (Read 359 times) |
|
Alincon
Full Member
member is offline
Posts: 147
|
|
inputCSV
« Thread started on: Nov 6th, 2016, 01:20am » |
|
I have been reading the 'Benefits' section of LBB. Is this a good use of inputcsv? (It seems to work as I intended) r.m.
Code:
INPUTCSV "|", #diary, trans$(t,1), trans$(t,2), trans$(t,3), trans$(t,4), trans$(t,5), trans$(t,6)
which replaces this:
Code:
line input #diary, trans$
for n = 1 to 6
trans$(t,n) = word$(trans$,n,"|")
if trans$(t,n) = "|" then trans$(t,n) = " "
next
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline
Posts: 147
|
|
Re: inputCSV
« Reply #1 on: Nov 6th, 2016, 01:28am » |
|
This looks like a better example of inputcsv: 1 line replaces 11.
r.m.
Code:
' line input #teacherFile, teacherRec$
' lname$ = word$(teacherRec$,1,".")
' fname$ = word$(teacherRec$,2,".")
' initial$ = word$(teacherRec$,3,".")
' gender$ = word$(teacherRec$,4,".")
' degree$ = word$(teacherRec$,5,".")
' major$ = word$(teacherRec$,6,".")
' minor$ = word$(teacherRec$,7,".")
' years$ = word$(teacherRec$,8,".")
' tenure$ = word$(teacherRec$,9,".")
' homeRoom$ = word$(teacherRec$,10,".")
INPUTCSV ".", #teacherFile, lname$,fname$,initial$,gender$,degree$,major$,minor$,years$,tenure$,homeroom$
|
|
Logged
|
|
|
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: inputCSV
« Reply #2 on: Nov 6th, 2016, 07:52am » |
|
What an incredibly powerful command! And I never even know it existed! (How many times am I going to say that!) There is ALWAYS so much more to learn. Although I HAVE used the InputTo$(#) function.
Jack
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: inputCSV
« Reply #3 on: Nov 6th, 2016, 09:45am » |
|
on Nov 6th, 2016, 01:20am, Alincon wrote:Is this a good use of inputcsv? |
|
It's a perfectly valid use, although of course you're relying on an LBB-specific extension (being able to specify a delimiter other than a comma) so it won't work in LB 4.5.0.
Sadly, as is well known (and documented at the LB Bug Tracker wiki), the implementation of INPUTCSV in LB 4.5.0 is broken anyway because it doesn't work if the item of data contains embedded quotes. So what promised to be a very useful addition - because it's quite difficult to code an accurate implementation of INPUTCSV in LB 4.04 - turned out to be a disappointment.
I know the LB folks hate me criticising Carl, and I do try not to be unfair, but in this case there's a Wikipedia page on the CSV file format in which examples of such files are listed. Had the LB 4.5.0 implementation been tested with these examples the problem would have been identified.
Anyway, INPUTCSV works correctly in LBB and I've added a couple of enhancements. Firstly you can specify a delimiter other than a comma, allowing for example a standard Tab Separated Value file (such as might be output by Excel) to be read. Secondly it accepts a CSV file with either Windows-style (CRLF) or Unix-style (LF) line terminations because you will commonly encounter the latter.
Richard.
|
|
|
|
|