[Gambas-user] Problem with CsvFile.Fields.Count
T Lee Davidson
t.lee.davidson at gmail.com
Sat Jul 16 18:06:30 CEST 2022
On 7/16/22 10:41, Safiur Rahman wrote:
> Thanks Charlie for your solution. After hForm.Read() provides me with a Columns list but also it takes to the first row of the
> dataset. So I have to close csv and again I have to Open csv and go to one by one row to fetch data.
Reading the data line by line is what you would need to do anyway. So, there must be a reason you need the Fields count prior to
iterating over the data lines.
It seems illogical to me that CsvFile.Eof is set True after the last line is read, instead of at the actual EOF. If it were set
at actual EOF, one could do something like this:
Public Sub Button1_Click()
Dim hForm As CsvFile
Dim cFields As Collection
hForm = New CsvFile("csv/8.tmp.csv", ";")
cFields = hForm.Read()
Print hForm.Fields.Count 'Process the fields count
Do
For Each sValue As String In cFields 'Process the current data line
Print Subst("&1: &2", cFields.Key, sValue)
Next
cFields = hForm.Read()
Loop Until hForm.Eof
End
Unfortunately, that does not work.
If you wanted to use the above code, Safiur, you could add an extra blank line at the end of the CSV file; ie. so that there are
two blank lines prior to actual EOF. (A messy hack at best, IMO.)
--
Lee
More information about the User
mailing list