Liberty BASIC Community Forum
« Input from a csv file »

Welcome Guest. Please Login or Register.
Dec 12th, 2017, 07:51am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Input from a csv file  (Read 116 times)
Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Input from a csv file
« Thread started on: Dec 7th, 2017, 09:03am »

Hello,
I am just new here. I use Liberty Basic on our farm for a couple off years. Now I want import a csv with cow data into LB so I can display it on displays in the milklabour.
I was trying with this code:

'Display a text file
filedialog "Open..." , "*.txt", filename$
open filename$ for input as #text
[loop]
if eof(#text) <> 0 then [quit]
input #text, item$
print item$
goto [loop]
[quit]
close #text
print "Done."
end

The problem here is, LB reads all fields and displays it under each other.. But I need to find the data back from each row.
If you have four fields in the csv file, I want something like this:
print aa$(1), ab$(1), ac$(1), ad$(1)
next cow is:
print aa$(2), ab$(2), ac$(2), ad$(2)
and cow fifty will be:
print aa$(50), ab$(50), ac$(50), ad$(50)

Line input will not work because it not always the same size.

For example the data off 10 cows:

1,,,,,,,22,Gekalfd,22
2,,95,,48,4.48,3.91,221,Drachtig,95
3,,,,60,5.33,4.07,213,Bewust gust,213
4,,,,36,4.8,4.11,223,Bewust gust,223
5,,,,790,4.98,3.21,81,Gekalfd,81
6,,7,12/12/2017,39,5.52,4.14,144,Geinsemineerd,7
7,,11,12/8/2017,364,4.56,3.52,155,Geinsemineerd,11
8,,82,,309,4.45,3.59,211,Drachtig,82
9,,109,,58,4.32,3.78,208,Drachtig,109
10,,199,,26,4.69,3.79,289,Drachtig,199

Thanks!!
« Last Edit: Dec 7th, 2017, 09:06am by Konijn » User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1708
xx Re: Input from a csv file
« Reply #1 on: Dec 7th, 2017, 1:02pm »

Read up help on
INPUTCSV
User IP Logged

damned Dog in the Manger
Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: Input from a csv file
« Reply #2 on: Dec 7th, 2017, 2:34pm »

Thanks ths73, I see it!! I have to upgraded
This was where I was looking for.

I made a test: But what am I doing wrong (newbe undecided)

open "c:\inlees.txt" for input as #readFile
for i = 1 to 150
inputcsv #readFile, a$(i), b$(i), c$(i), d$(i), e$(i), f$(i), g$(i)
next i
for i = 1 to 150
print a$(i)
print b$(i)
print c$(i)
print d$(i)
print e$(i)
print f$(i)
print g$(i)
next i
close #readFile
end
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2289
xx Re: Input from a csv file
« Reply #3 on: Dec 7th, 2017, 4:33pm »

If you're using arrays with more than 10 elements, you have to use the DIM command to give them a size.

Code:
dim a$(150)
'...etc. 


Something like this, you may want to look into double-dimensioned arrays, as well.
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: Input from a csv file
« Reply #4 on: Dec 8th, 2017, 11:07am »

Thanks Chris,

I made this:
open "c:\inlees.txt" for input as #readFile
dim a$(150)
dim b$(150)
dim c$(150)
dim d$(150)
dim e$(150)
dim f$(150)
dim g$(150)
dim h$(150)
dim i$(150)
dim j$(150)
dim k$(150)
for i = 1 to 150
inputcsv #readFile, a$(i), b$(i), c$(i), d$(i), e$(i), f$(i), g$(i), h$(i), i$(i), j$(i), k$(i)
for i = 1 to 150
print a$(i)
next i
close #readFile
end

I think I do it wrong! It stock on for i = 1 to 150
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1708
xx Re: Input from a csv file
« Reply #5 on: Dec 8th, 2017, 12:25pm »

You have two FOR but only one NEXT
So it should be along this
Code:
open "c:\inlees.txt" for input as #readFile
dim a$(150)
dim b$(150)
dim c$(150)
dim d$(150)
dim e$(150)
dim f$(150)
dim g$(150)
dim h$(150)
dim i$(150)
dim j$(150)
dim k$(150)

for i = 1 to 150
inputcsv #readFile, a$(i), b$(i), c$(i), d$(i), e$(i), f$(i), g$(i), h$(i), i$(i), j$(i), k$(i)
next i   '<-- added line

for i = 1 to 150
print a$(i)
next i

close #readFile
end 
User IP Logged

damned Dog in the Manger
Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: Input from a csv file
« Reply #6 on: Dec 8th, 2017, 2:30pm »

Thanks tsh73, I was to hasty lipsrsealed

Now I can go on. I scan with an RFID scanner the transponders, send it with bluetooth to LB and LB gets the info from the readed csv file and send as udp over internet to an arduino with tft screen back to the place were I am. I hope its gonna work.
Thanks for the help!!
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls