import csv file and rename columns
Posted: Wed May 22, 2013 3:59 pm
i am able to import the data from csv file OK. the file has no header column record.
On the first import, the column names were "Col 1" ... "Col ##"
I put in set dgColumnName statements to rename the columns, but not all of them happened.
Now I am left with a datagrid that has partial column renames.
When I run the code, it appears that if the set command fails, the rest of the code does not execute.
How can I "trap" this apparent error and let the remaining statements execute.
In Visual Basic and Java, there is a "try-catch" methodology.
CODE:
on mouseUp
-- locate the CSV file for the data grid (dgKnights)
local tFileName
answer file "Please choose a file to import" with type "Comma Separeted Values|csv|CSV"
if the result is not "cancel" then
-- save the FilePathName
put it into tFileName
-- get the contents of the CSV file
put URL ("file:" & tFileName) into tFileContents
-- display the file contents in the data grid
replace comma with tab in tFileContents
set the dgText[false] of group "dgBaseRec" to tFileContents
-- rename the columns for BaseRec file
set dgColumnName ["Col 1"] of group "dgBaseRec" to "ID Number"
set dgColumnName ["Col 2"] of group "dgBaseRec" to "RelationLink"
set dgColumnName ["Col 3"] of group "dgBaseRec" to "AddressLink"
... rest of code now shown
end if
end mouseUp
Thank you
bill
On the first import, the column names were "Col 1" ... "Col ##"
I put in set dgColumnName statements to rename the columns, but not all of them happened.
Now I am left with a datagrid that has partial column renames.
When I run the code, it appears that if the set command fails, the rest of the code does not execute.
How can I "trap" this apparent error and let the remaining statements execute.
In Visual Basic and Java, there is a "try-catch" methodology.
CODE:
on mouseUp
-- locate the CSV file for the data grid (dgKnights)
local tFileName
answer file "Please choose a file to import" with type "Comma Separeted Values|csv|CSV"
if the result is not "cancel" then
-- save the FilePathName
put it into tFileName
-- get the contents of the CSV file
put URL ("file:" & tFileName) into tFileContents
-- display the file contents in the data grid
replace comma with tab in tFileContents
set the dgText[false] of group "dgBaseRec" to tFileContents
-- rename the columns for BaseRec file
set dgColumnName ["Col 1"] of group "dgBaseRec" to "ID Number"
set dgColumnName ["Col 2"] of group "dgBaseRec" to "RelationLink"
set dgColumnName ["Col 3"] of group "dgBaseRec" to "AddressLink"
... rest of code now shown
end if
end mouseUp
Thank you
bill