I'm trying to import a tab delimited text file and extract the three columns. The first row contains the column headings. I can import the text fine but if there is a comma in the field livecode treats this as the end of the field.
My data is set up as follows:
Name Job Company
David CEO abc
Tim CEO, COO def
The first entry imports correctly, but the second one stops just before the comma and then doesn't import the company name
Here's my code:
Code: Select all
on mouseUp
answer file "A text file" with type ("text files|txt|tTXT" & return & "all files|*|*")
if it <> "" then
put it into theFilePath
put url ("file:" & theFilePath) into tCardNames
else
--no file was selected, or cancel was pressed
beep
end if
repeat with i = 2 to the number of lines of tCardNames
put item 1 of line i of tCardNames into tFields
createNamedButton i, tFields
end repeat
put (i-1) into field fCSVButtons //store how many buttons were created
end mouseUp
on createNamedButton n, aFields
replace tab with return in aFields
create button "btn"&(n-1)
put item 1 of line 1 of aFields into aName
put item 1 of line 2 of aFields into aTitle
put item 1 of line 3 of aFields into aJob
put cr into aTitleWrap
put wordWrapped (aTitle, 25) after aTitleWrap
set the label of it to aName &return & aTitleWrap&return & aJob
set the width of it to 150
set the height of it to 100
end createNamedButton
Thanks