Why don't either of these work? When I get to the end of the file I still get an 'input past end of file' error.
if I only read in 2 array$ instead of 3, it works, so obviously the last bit of inf$ is missing. Although it doesn't appear to be, I still see 3 bit of info in each line
I realise that I could read the info in as one line and then split the info, but there must be a simpler way? I want to read various '.csv', so how can I prevent the error without having to manually check the '.csv' and add a file check at the end. e.g. if x$ = "-1" then [quit]
open f$ for input as #rd [loop] if eof(#rd) <> 0 then [quit] inputcsv #rd, dt$,am$,inf$ print "Info -> ";dt$,am$,inf$ goto[loop] [quit] close #rd
open f$ for input as #rd do if eof(#rd) <> 0 then [quit] inputcsv #rd, dt$,am$,inf$:transac = transac +1 print "Info -> ";dt$,am$,inf$ loop while eof(#rd) = 0 [quit] close #rd
Post by Brandon Parker on May 15, 2021 21:54:28 GMT -5
Try this one as a replacement for your first example and try to work out what is different. If you need further assistance or can not figure it out just let us know.
This assumes you have three columns in your CSV file. It then prints the information to the MainWin after retrieving each row. Open f$ For Input As #rd While Not(EOF(#rd)) InputCSV #rd, dt$,am$,inf$ Print Trim$(dt$);", ";Trim$(am$);", ";Trim$(inf$) Wend close #rd
Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
Hmm....... I still got the same error! If i only load 1/2 the files then I don't get the error - obviously. If I use input# or Line input# and only 1 array or 2 arrays then I don't get and error, but the moment I add the 3rd array it wont work, unless I use On Error goto I'm sure it's something painfully obvious, but I can't see it!
Is there a way I can determine the length of the file before reading it in - LOF#rd, perhaps? Although, I don't think that will help!
A CSV is only supposed to have the CSV data in it. I am guessing that when you wrote the file you allowed additional characters like CRLF to be appended to a final comma. That being the case you will read in the last record set but you will not be at eof() then the code tries to read three more items but only finds one. So are there any hidden characters or spaces appended to the file?
Well, there doesn't seem to be anything extra. I loaded it into a texteditor and it doesn't show anything extra.Word isn't showing any extra hidden characters etc. Also used Directory Opus which loads and reads all types of files, but it appeared to be fine. I didn't write the file myself. I could try writing it myself to see if it improves the situation! I read and load ".csv" files all the time and have never had this problem!
Just rewrote the file to disk and now it loads fine, so there must be extra characters, as you say. Looks like I'll have to add an extra option to load and rewrite the file when it's used for the first time, unless there's another way.
Ohhh Sorry,..... I thought you meant use the option in Word which turns on/off hidden characters/spaces/formatting, etc. if you go into options/display. I which case I'm more at a loss than before. Your code didn't seem to display anything I really understood, just the usually "/' etc
I'll just use my last idea and rewrite the '.csv' before its used the first time. it only takes a few seconds Thanks for your time and help, Rod and Brandon