|
Post by pandawdy on Jul 16, 2019 8:35:38 GMT -5
Is it possible to select lines in a CSV file to load?
For example, lets say this is the CSV file I'm working with: one, two, three four, five, six
When using INPUTCSV, is it possible to select the second line only? Or do all values have to be loaded first?
It seems like this should involve an array but I don't understand how to use arrays very well.
|
|
|
Post by Rod on Jul 16, 2019 8:46:45 GMT -5
Spend some time reading and playing with the RAF file handling example in the help file. That lets you put and get individual lines of data from deep within a file.
|
|
|
Post by alincon on Jul 16, 2019 14:40:30 GMT -5
Have you studied the inputcsv command in the LB help file? The examples make it pretty clear how to get any particular line from a csv file.
r.m.
|
|
|
Post by pandawdy on Jul 16, 2019 18:43:55 GMT -5
Have you studied the inputcsv command in the LB help file? The examples make it pretty clear how to get any particular line from a csv file. r.m. Yes I did read the help file. I must have been missing something. Still don't see it.
|
|
|
Post by metro on Jul 16, 2019 19:13:45 GMT -5
It is a bit hard to find because it is under new features in LibertyBasic 4.5.0 I think the online help needs to be updated to match the help document you have with your install.
|
|
|
Post by metro on Jul 16, 2019 20:01:01 GMT -5
down here we would say you're one kangaroo short in the top paddock nah only joking
for me I would either use an array and line input the data you can then use WORD$ to find your match within your array based upon your search criteria or for huge data sets insert them into a SQlite DB and search for s specific field/record Arrays: Line Input now allows input directly multiple variables and arrays. j=0 : i=0 filedialog "Open","*.txt",file$ if file$="" then end dim a$(3000) open file$ for input as #f while not(eof(#f)) line input #f, a$(i) i=i+1 wend close #f for j=0 to i print a$(j) ' for the fifth line print a$(4) next end
|
|
|
Post by alincon on Jul 16, 2019 20:40:27 GMT -5
I believe that inputcsv retrives as many items from a file as there are variable names following "inputcsv" (if you have more variable names than file items, you'll get an error) But you don't need an array, you can work with the variables directly; something like this:
If memberName$ = "Smith" then memberCount = memberCount + 1
r.m.
|
|
|
Post by metro on Jul 16, 2019 22:35:36 GMT -5
I believe that inputcsv retrives as many items from a file as there are variable names following "inputcsv" (if you have more variable names than file items, you'll get an error) But you don't need an array, you can work with the variables directly; something like this: If memberName$ = "Smith" then memberCount = memberCount + 1 r.m. Now I'm curious, If I am understanding the problem correctly pandawdy wants to choose a line from the CSV file, lets say line 3 ie a$(2) I guess he could just iterate through the file till the index hits the line number he wants and just pull that line to print or manipulate. But I assumed that this maybe a repeatable query of the same data file (maybe I should not assume) so therefore having it sit in an array may be easier to repeat the process. Or if he was looking for a line that contained JR (for example) as the first field maybe the following would work
a$(0)="QW,AZ,PB,YG,LE,EW,TV,RB,NW,VZ,ER,TP,MF,ZS" a$(1)="TE,TI,ZO,BU,KQ,UT,RH,IU,BG,YO,EF,SM,UW,QF" a$(2)="JR,VH,IO,YI,CQ,DJ,JL,CO,WN,OU,OV,YT,YD,AY" a$(3)="MI,JB,OW,TF,EM,UM,RB,YO,SH,YQ,BH,YW,LB,QN"
find$="JR"
FOR count = 0 to 3 if WORD$(a$(count),1,",")=find$ then PRINT a$(count) end if next FOR count = 0 to 3 if count = 2 then PRINT a$(count)
next
|
|
|
Post by Rod on Jul 17, 2019 4:12:20 GMT -5
What if CSV was the wrong tool for the job?
|
|
|
Post by pandawdy on Jul 17, 2019 13:08:50 GMT -5
I could have swore I wrote a response and it never showed up.. anyhow.. I think in this case a random access data file might work better. Appreciate all the help.
|
|