Using CsvFile.Fields
Posted
#1
(In Topic #1206)
Trainee
I'm using CsvFile to read some quite large CSV files and all is okay apart from CsvFile.Fields.
I notice in the documentation that field names are set to lower case, why is this?
In the files I am using all the field names are capitalised, some are all capitals (acronyms for example), so to have them convert to all lower case is causing a bit of a problem.
Is there a way of converting field names to their original format?
Thanks all
Pusherman
Posted
Guru

/comp/gb.util/csvfile/keepnames - Gambas Documentation
/comp/gb.util/csvfile - Gambas Documentation
Posted
Trainee
If I say myCSVfile.KeepNames=True then myCSVfile.Fields just returns #0
What am I missing, here?
Posted
Guru

pusherman said
Thanks, but at the risk of sounding dumb I can't figure out what format KeepNames takes.
If I say myCSVfile.KeepNames=True then myCSVfile.Fields just returns #0
What am I missing, here?
No idea, i've never used CsvFile
according to doc it's just a simple boolean switch.
wiki said
Property KeepNames As Boolean
Since 3.17
Return or set if field names are kept unchanged or not.
If this property is set, the NoDiacritics property is ignored.
I assume you have 3.17+
It's possible there's a bug but nobody is really using the CsvFile.class so it's not been reported yet.
Posted
Trainee
I have a work-around that's okay for me. I'm reading the first line of the file with a simple Line Input and substituting what I've read with what .Fields gives me.
Thanks, again.
Posted
Guru

Posted
Guru

I just submitted a fix.
Update CsvFile.class, fix error when using KeepNames (!338) · Merge requests · Gambas / gambas · GitLab
the code was this…
Code (gambas)
- $aField[iInd] = sField
but should be this…
Code (gambas)
- $aField[iInd] = sField
The sField was never set if using KeepNames so i moved it to before the If condition.
I've attached the fixed CsvFile.class if you fancy testing it works
Posted
Guru

Posted
Guru

But…
If you may need your program to work on older gambas versions than 3.19.1 then do not use CsvFile.class from gb.util but place the CsvFileFix.class i uploaded into your programs source folder (rename it if you want) and use that class instead.
Posted
Trainee
Thanks for your help, guys.
Posted
Guru

Note: there was a bug in the fixed file i uploaded because i gave it a different name.
Commands like CsvFileFix.Open() returned a CsvFile object not a CsvFileFix object because i did not replace all the "CsvFile" text in the class to be "CsvFileFix"
So i re-uploaded the fixed version , but if you rename the class file you must change all the words in the class from "CsvFileFix" to whatever you name it.
1 guest and 0 members have just viewed this.



