Page 1 of 1

error checking or trapping when writing text file

Posted: Sat Jul 21, 2007 8:03 pm
by derek
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

Posted: Sat Jul 21, 2007 8:54 pm
by Klaus
Hi Derek,

"the result" is always empty when the action was succesful and will contain a hint on what might have gone wrong if not.


Regards

Klaus

Posted: Sat Jul 21, 2007 9:27 pm
by derek
Thank you, Klaus. And thank you for explaining the use of the URL statement in another thread (newbie question; write to file, read from file?). That helped me make my script above work properly.

Derek

Posted: Sat Jul 21, 2007 9:35 pm
by Klaus
Glad I could help, Derek :-)