Code: Select all
global fileData, newData,
on mouseUp
put empty into fileData
put empty into newData
readFile @fileData, @newData
end mouseUp
on readFile @fileData, @newData
//Ask the user for the file in question and use the location
//of the file to put the contents into the variable fileData
answer file "Please choose the file to read..."
if the result is not "Cancel" then
put it into fileLocation
put url("file:" & fileLocation) into newData
else if the result = "Cancel" then
exit to top
end if
//Split and organise the filedata into a 2-D array
local loop, tempData
repeat with loop = 0 to the number of lines of newData
//Take each line and split it into each individual component
//and store it in its correct position in the 2D array.
put line loop of newData into tempData
split tempData by comma
put tempData[1] into fileData[loop][1]
put tempData[2] into fileData[loop][2]
put tempData[3] into fileData[loop][3]
put tempData[4] into fileData[loop][4]
end repeat
//Check the read was successful
//If so, enable the button to display the information
//If not, display message and quit
if fileData is not empty then
answer info "File read sucessfull!"
enable button "processbtn"
else
answer error "Something went wrong.."
exit to top
end if
I feel like its something pretty stupid that I'm overlooking, but any help would be appreciated.
Thanks