This text have been created yesterday and I add more data + relevant code today, minutes ago (10:00).
You may skip part 1 and have a look at the code.
The code as is works fine provided you load a two fields / line csv files, but have a display bug if the file have more than two fields / row (and I only display two fields from each Row).
I can reject the user selected csv file if I found more than two fields in each row, but I want to understand why a weird display occured in this circumstance (my bug or Xojo bug).
Nota: I shut down, wait a minute, power on the MacBook pro, run Xojo (only) run the application in the IDE and saw the bug.
Then, I shutdown Xojo, power off the computer.
I powered on the computer, clear the trash, runx Xojo, open the project, run it in the IDE and found the same bug.
Remember: this code (a bit different / more lines ferom the original / some non relevant lines changed) displays the same bad behavior than the one I have in my project.
Specifically, I added two new variables to hold the string length - for Cell(0), Cell(1) - removed the try part, removed the core text line reading since the but appears since I read line 1, etc.
At last, I am pleased using two quotes a field to enclose each field and the comma as field delimiter.
Take this as a quizz: who have a bug ? My code (me) or Xojo ?
[yesterday] Not really a quiz (I do not have the answer, yet), but here I go:
think a proprietary application that loads one field a line .txt files or two fields a line .csv file (comma separated and quote enclosed).
Time ellapsed and you are near the end of releasing it.
Now is the time to make intensive testings and be creative.
After some days, I am really happy and think it is time to end writting the users manual.
BTW: what if I get some csv files from the internet and check these ? Of course, testing with my own csv files is not enough. I was happy to test my application about weird csv files. So, lets go !
Lord, oh my Lord ! Why ? Why do I found a bug at this stage ? I loose the last character of the second field on these csv files. Why ?
Now the quest. Before going to the code in the project, I am trying to understand whats wrong in that file, what this file have that mine does not ?
The only difference is the presence of some Return character and they have more than two fields in each line.
It does not matter: I just have to add a third field ! I started to add a third heading field, load the file and everything is OK.
That is not enough: I added another third field, but this time in the core data (first line only): I open the file and I MISS ThE LAST CHARACTER OF THE SECOND COLUMN ! (.ra instead of .rar is not correct at all !).
Now the quest search starts.
BTW: the code
In a loop, I read the .csv text file, one line after another. I use two NthFields to get strings for columns 0 and column 1, leaving the rest of the line where it was. After all, how a code that works perfectly for a line with two fields will make strange results ?
What is your answer ?
In the mean time (now to the moment I send this text), I will try to understand the why of the thing.
Adding a third field in the Heading does not reveal an error.
Adding a third field in the first line reveal an error.
Removing the third field in the Heading does not remove the error.
[today, 10:00] Last found bit of information:
the heading(1) string is truncated by 1 character if the csv file have more than 2 fields / line. No need to load more than line 1 to get the bug.
The relevant code is:
[code] Dim ImportFI As FolderItem
Dim ImportTIS As TextInputStream
Dim ALine As String
Dim LocRow As Integer
Dim TheURL As String
Dim TheName As String
Dim URLLen As Integer
Dim NameLen As Integer
Dim MyDelimiter As String
MyDelimiter = Chr(34) + “,” + Chr(34)
// Get a csv file
ImportFI = GetOpenFolderItem(“text/csv”)
// a. Get A TextInputStream Reference and set the encodings to UTF-8 ImportTIS = TextInputStream.Open(ImportFI) ImportTIS.Encoding = Encodings.UTF8 // b. Get one line of text from the csv text file ALine = ImportTIS.ReadLine // c. Compute Cell(0) string and its length TheURL = NthField(ALine, MyDelimiter, 1) + Chr(34) URLLen = Len(TheURL) // d. Compute Cell(1) string and its length TheName = NthField(ALine, MyDelimiter, 2) + Chr(34) NameLen = Len(TheName) // e. Fills the header LB.Heading(0) = Mid(TheURL,2,Len(TheURL)-2) // Heading(0) LB.Heading(1) = Mid(TheName,1,Len(TheName)-2) // Heading(1) Return[/code]
The csv file text can be:
"Head 0","Head 1","Head 2"
"Line 1","Line 1","Line 1"
"Line 2","Line 2","Line 2"
"Line 3","Line 3","Line 3"
To get the correct results, just remove the last field to get only two by line:
"Head 0","Head 1"
"Line 1","Line 1"
"Line 2","Line 2"
"Line 3","Line 3"
BTW: my external csv testing file (taken from the internet) have far more than three fields a line, but these are enough to display the bug.