CSV icon indicating copy to clipboard operation
CSV copied to clipboard

CSV_Identifier name collision with multiple CSV files

Open Ethan-Burchett opened this issue 4 years ago • 1 comments

HI, just to start, this CSV library is great and does a lot of good things.

I think I found an issue when you try to use CSV_Load on two different .csv files in one .ahk program.

The second call of CSV_Load, the CSV_Identifier overwrites the first CSV_Identifier.

You can still access the data members of the second CSV_Identifier but use the first CSV_Identifier.

EX

CSV_Load("\Job Folder\jobFolderPaths.csv", JobFolderPathData,",") -> JobFolderPathData is the 1st CSV_Identifier

CSV_Load("\Job Folder\JobListPath.csv", CompanyIndex ,",") -> CompanyIndex is the 2nd CSV_Identifier

If you call CSV_FileName(JobFolderPathData) (1st CSV_Identifier) you will return the file name of CompanyIndex (1st CSV_Identifier)

This issue persists even if each CSV_Load() is in it's own .ahk file.

Thanks EB

Ethan-Burchett avatar Jun 26 '21 16:06 Ethan-Burchett

JobFolderPathData and CompanyIndex need to be quoted, so "JobFolderPathData" and "CompanyIndex" (unless they are variables, but I suspect they aren't)

Test script to illustrate it works:

#NoEnv
#SingleInstance, force
#Include CSV.ahk ; place this script and CSV.ahk in the same folder for it to work
                 ; or create a LIB folder where you have your scripts - https://www.autohotkey.com/docs/Functions.htm#lib

; Creating an example CSV file
FileDelete, ExampleCSVFile1.csv
FileAppend,
(
Year,Make,Model,Description,Price
1997,THISCELL-Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
1996,Jeep,Grand Cherokee,"MUST SELL! air, moon roof, loaded",4799.00
), ExampleCSVFile1.csv


FileDelete, ExampleCSVFile2.csv
FileAppend,
(
"Joan ""the bone"", Anne",Jet,"9th, at Terrace plc",Desert City,CO,00123
"John ""Da Man""",THISCELL-Repici,120 Jefferson St.,Riverside, NJ,08075
John,Doe,120 jefferson st.,Riverside, NJ, 08075
Jack,McGinnis,220 hobo Av.,Phila, PA,09119
Stephen,Tyler,"7452 Terrace ""At the Plaza"" road",SomeTown,SD, 91234
,Blankman,,SomeTown, SD, 00298
"John ""the bone"", Anne",Jet,"9th, at Terrace plc",Desert City,CO,00123
), ExampleCSVFile2.csv

CSV_Load("ExampleCSVFile1.csv","data") ; note the "quotes" around the identifier data
CSV_Load("ExampleCSVFile2.csv","test") ; note the "quotes" around the identifier test

; again use quotes when using the identifier:
MsgBox % CSV_FileName("data") " Rows:" CSV_TotalRows("data") ", Data cell 2,2: " CSV_ReadCell("data",2,2) "`n" CSV_FileName("test") " Rows:" CSV_TotalRows("test") ", Test cell 2,2: " CSV_ReadCell("test",2,2) "`n"

ExampleCSVFile1.csv Rows:5, Data cell 2,2: THISCELL-Ford ExampleCSVFile2.csv Rows:7, Test cell 2,2: THISCELL-Repici

hi5 avatar Jun 26 '21 16:06 hi5