error checking or trapping when writing text file
Posted: Sat Jul 21, 2007 8:03 pm
I'm wondering about error checking/trapping when writing a text file. The sample stack, "Multiple Choice Questionnaire" contains the code:
-- check for an error
if word 1 of the result is "error" then
However, I am getting a result "can't open file." Therefore, using the RunRev code sample above, the error is not detected.
I changed to the code below, which I guessed at. I was hoping that a successful writing of the file would return no result, and that any returned words would trigger the error part of the if statement.
It seems to work. But I wonder if it is reliable, and if there is a better way to verify that a text file has been written successfully. Any comments are welcome. I'm using version 2.7.4 on OS 10.4.9.
Thanks,
Derek
on mouseUp
global gNameData, gIDdata
put field "display" into URL ("file:results/" & gNameData & gIDdata & ".txt")
if the result is "" then
answer "Your results were uploaded successfully."
else
answer "There was an error uploading your quiz result. Contact attendant."
end if
end mouseUp
-- check for an error
if word 1 of the result is "error" then
However, I am getting a result "can't open file." Therefore, using the RunRev code sample above, the error is not detected.
I changed to the code below, which I guessed at. I was hoping that a successful writing of the file would return no result, and that any returned words would trigger the error part of the if statement.
It seems to work. But I wonder if it is reliable, and if there is a better way to verify that a text file has been written successfully. Any comments are welcome. I'm using version 2.7.4 on OS 10.4.9.
Thanks,
Derek
on mouseUp
global gNameData, gIDdata
put field "display" into URL ("file:results/" & gNameData & gIDdata & ".txt")
if the result is "" then
answer "Your results were uploaded successfully."
else
answer "There was an error uploading your quiz result. Contact attendant."
end if
end mouseUp