error checking or trapping when writing text file

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
derek
Posts: 17
Joined: Tue Oct 17, 2006 9:39 pm

error checking or trapping when writing text file

Post by derek » 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
Derek Roff
Language Learning Center
University of New Mexico

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sat Jul 21, 2007 8:54 pm

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

derek
Posts: 17
Joined: Tue Oct 17, 2006 9:39 pm

Post by derek » Sat Jul 21, 2007 9:27 pm

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
Derek Roff
Language Learning Center
University of New Mexico

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Sat Jul 21, 2007 9:35 pm

Glad I could help, Derek :-)

Post Reply